Giter Club home page Giter Club logo

Comments (19)

phayes avatar phayes commented on June 10, 2024

Can you paste the WKT that is in $sWkt?

from geophp.

phayes avatar phayes commented on June 10, 2024

Or put it in a pastebin somewhere?

from geophp.

HendrikN avatar HendrikN commented on June 10, 2024

The guilty WKT:

POLYGON((4.8352495472368009 52.3561217600921438,4.8354139113045580 52.3561243429663534,4.8356082266282945 52.3561267417385281,4.8358010085903622 52.3561273083083663,4.8358010085903622 52.3561273083083663,4.8358035242637225 52.3559935212917722,4.8363777606561538 52.3559985348227173,4.8365863082998608 52.3560003600829731,4.8365523717335313 52.3570990145454189,4.8365884597636066 52.3572643433297529,4.8366320506970659 52.3574639095218686,4.8366736405531485 52.3576544056339870,4.8367264446828226 52.3578947700094304,4.8367922739966023 52.3581940807800450,4.8368228816936947 52.3583326871276356,4.8368228816936947 52.3583326871276356,4.8346348012064322 52.3583075969840550,4.8346348012064322 52.3583075969840550,4.8346348010943823 52.3583076059723282,4.8346348010943823 52.3583076059723282,4.8344931735728114 52.3583059732702338,4.8343773230572911 52.3583046496785585,4.8342182417472204 52.3583028092031384,4.8340047277034000 52.3583004442080195,4.8340047277034000 52.3583004442080195,4.8340047286008216 52.3583003723016063,4.8340047286008216 52.3583003723016063,4.8333843154510516 52.3582932434377639,4.8333843154510516 52.3582932434377639,4.8333915914677918 52.3580669388087898,4.8333968982183286 52.3578913129544787,4.8334415565569193 52.3563602568407660,4.8336003450092706 52.3563614767834267,4.8336013166539615 52.3563318721204567,4.8336013166539615 52.3563318721204567,4.8339582156582548 52.3563361223319603,4.8339656498645338 52.3561015845598732,4.8340692910524092 52.3561032110135258,4.8340692910524092 52.3561032110135258,4.8345511248958477 52.3561107854074095,4.8345511248958477 52.3561107854074095,4.8345513450958055 52.3561107864365809,4.8345513450958055 52.3561107864365809,4.8346742584771087 52.3561127181661092,4.8346742584771087 52.3561127181661092,4.8347750227755597 52.3561143035917596,4.8347750227755597 52.3561143035917596,4.8352495472368009 52.3561217600921438))

from geophp.

phayes avatar phayes commented on June 10, 2024

So the problem is that running simplify on that polygon result in a NULL set EMPTY geometry. We need to add support for a new type of Geometry called Empty.

from geophp.

phayes avatar phayes commented on June 10, 2024

I'll work on this as soon as I get time

from geophp.

phayes avatar phayes commented on June 10, 2024

Okay, this should now be fixed in the master branch. Please test!

from geophp.

phayes avatar phayes commented on June 10, 2024

Any luck @HendrikN ?

from geophp.

HendrikN avatar HendrikN commented on June 10, 2024

Well, it returns something:

POLYGON EMPTY

However, i still don't understand why this is the expected output of simplyfing a polygon and retrieving the WKT. Can you explain this to me (like i'm 12 ;) ).

from geophp.

phayes avatar phayes commented on June 10, 2024

Ha! Sure. :-)

What is not well documented is that the variable you are passing in (1.5) is the * tolerance*. (I've just added this documentation now to the API page). The simplify method will trim as many vertices out of the geometry as it can while maintaining that the resulting geometry is within the passed tolerance in relation to the orignal geometry.

It looks to me that your geometry is in lat/lon projection (SRID=4326). By calling simplify(1.5), you are asking geoPHP to trim this geometry until the resulting geometry is within 1.5 decimal-degrees (several hundred km) of the original - however your orignal geometry is way less than that end-to-end. The simplify method dutifully does what you are telling it to do and simplifying the geometry down to nothing!

Try passing in a much smaller tolerance and see what happens.

from geophp.

HendrikN avatar HendrikN commented on June 10, 2024

Right, thanks for explaining! My guess is that there is no "safe" universal tolerance I could use for my applications... So, is there a way to simplify a polygon with respecting the topology? I know MapServer/GEOS has support for it.

from geophp.

phayes avatar phayes commented on June 10, 2024

Hi,

Would you be willing to point me at some documentation for these functions in GEOS / MapServer?

I would certainly accept a patch for a method called (for example) simplifyCoarse($ratio), that would take a float (between 0 and 1), and just naively delete that ratio of vertices from the geometry. For example, $geom->simplifyCoarse(0.5) , if applied against a linestring, would remove every second point, while making sure to preserve the first and last point (to keep topology the same).

from geophp.

HendrikN avatar HendrikN commented on June 10, 2024

Here you are:

MapScript: http://mapserver.org/mapscript/php/index.html#shapeobj (topologySimplifyPreservingSimplify)
GEOS: http://geos.osgeo.org/doxygen/classgeos_1_1simplify_1_1TopologyPreservingSimplifier.html

from geophp.

phayes avatar phayes commented on June 10, 2024

Hi @HendrikN,

So there's no direct support for these methods directly in the PHP bindings. See here for a list of all methods:

https://github.com/strk/geos/blob/master/php/geos.c

However, try calling: $oGeometry->simplify(1.5, TRUE);

The second TRUE parameters forces the simplify function to preserve topology. Give it a shot and let me know if it works for you.

from geophp.

phayes avatar phayes commented on June 10, 2024

It's a month with no response. Closing this issue - please feel free to re-open

from geophp.

iamginpy avatar iamginpy commented on June 10, 2024

cant simplify this one. this is sandiego city POLYGON ((-98.2501459 27.751617, -98.2500949 27.751855, -98.2498929 27.752822, -98.2498189 27.752976, -98.2495739 27.75289, -98.2483579 27.752464, -98.2479529 27.752322, -98.2479149 27.752458, -98.2478039 27.752866, -98.2477669 27.753003, -98.2474749 27.753965, -98.2473509 27.754377, -98.2470789 27.755278, -98.2468759 27.755948, -98.2459739 27.755664, -98.2450149 27.755363, -98.2448389 27.75588, -98.2446509 27.756435, -98.2445559 27.756716, -98.2438089 27.756598, -98.2437589 27.756591, -98.2435459 27.757038, -98.2434329 27.757209, -98.2430949 27.757724, -98.2429829 27.757896, -98.2429209 27.758089, -98.2427369 27.75867, -98.2426759 27.758864, -98.2425839 27.759276, -98.2424559 27.759851, -98.2431169 27.759701, -98.2435299 27.759608, -98.2439049 27.759477, -98.2439329 27.759468, -98.2444569 27.75843, -98.2446369 27.758076, -98.2447239 27.757746, -98.2448249 27.75737, -98.2454569 27.75739, -98.2457979 27.757402, -98.2463139 27.757407, -98.2478649 27.757425, -98.2480759 27.757428, -98.2482819 27.757655, -98.2483159 27.757686, -98.2484199 27.757779, -98.2484549 27.757811, -98.2484599 27.757782, -98.2484749 27.757695, -98.2484799 27.757666, -98.2485539 27.757682, -98.2486039 27.75771, -98.2487579 27.757864, -98.2488639 27.757985, -98.2489319 27.758177, -98.2489439 27.758282, -98.2489439 27.758419, -98.2489119 27.758628, -98.2488519 27.75903, -98.2487959 27.759228, -98.2485989 27.759762, -98.2484689 27.759949, -98.2483199 27.760087, -98.2481599 27.760159, -98.2480789 27.760203, -98.2480169 27.760252, -98.2479679 27.760368, -98.2478199 27.760627, -98.2477269 27.761017, -98.2476649 27.761336, -98.2476839 27.761727, -98.2476869 27.761737, -98.2477149 27.761821, -98.2478509 27.762052, -98.2478819 27.76214, -98.2479379 27.762541, -98.2480199 27.762846, -98.2478639 27.76331, -98.2473969 27.764702, -98.2472419 27.765167, -98.2471769 27.765374, -98.2469839 27.765998, -98.2469209 27.766206, -98.2466439 27.767081, -98.2458149 27.769705, -98.2455389 27.770581, -98.2454329 27.77093, -98.2451179 27.771979, -98.2450139 27.772329, -98.2448919 27.772713, -98.2446319 27.773531, -98.2444639 27.773492, -98.2402729 27.77253, -98.2388759 27.77221, -98.2381849 27.772033, -98.2361139 27.771502, -98.2354239 27.771325, -98.2352279 27.771274, -98.2346399 27.771124, -98.2344449 27.771074, -98.2327919 27.770655, -98.2285769 27.769589, -98.2284849 27.769558, -98.2286909 27.769001, -98.2287169 27.76893, -98.2293079 27.767331, -98.2295239 27.766852, -98.2301749 27.765414, -98.2303919 27.764936, -98.2304269 27.764832, -98.2305349 27.76452, -98.2305719 27.764417, -98.2305959 27.764344, -98.2306119 27.7643, -98.2306629 27.764125, -98.2306849 27.764052, -98.2307029 27.763991, -98.2307409 27.763871, -98.2309149 27.763332, -98.2309399 27.763255, -98.2309769 27.763154, -98.2309689 27.762965, -98.2312019 27.762332, -98.2312879 27.762209, -98.2313129 27.762133, -98.2313919 27.761905, -98.2314179 27.76183, -98.2310749 27.761956, -98.2307489 27.762077, -98.2300249 27.761897, -98.2296709 27.761809, -98.2295479 27.761785, -98.2298649 27.760178, -98.2307449 27.755737, -98.2309459 27.755786, -98.2314829 27.755919, -98.2325089 27.756173, -98.2331939 27.756344, -98.2334799 27.755545, -98.2334959 27.755502, -98.2328769 27.75525, -98.2328079 27.755222, -98.2324009 27.755085, -98.2310759 27.75502, -98.2305599 27.754996, -98.2305819 27.754666, -98.2305919 27.754543, -98.2312679 27.75438, -98.2313289 27.754338, -98.2316599 27.754116, -98.2318929 27.753995, -98.2321689 27.753712, -98.2335819 27.754505, -98.2343609 27.754942, -98.2343609 27.754176, -98.2343649 27.752262, -98.2343509 27.751881, -98.2343249 27.751123, -98.2343249 27.751117, -98.2342979 27.750372, -98.2342959 27.750303, -98.2341909 27.748141, -98.2341549 27.747398, -98.2341499 27.747306, -98.2341369 27.747031, -98.2341329 27.74694, -98.2342779 27.746941, -98.2347129 27.746944, -98.2348579 27.746945, -98.2372289 27.746957, -98.2443439 27.746993, -98.2467159 27.747006, -98.2470359 27.747007, -98.2470289 27.747041, -98.2468419 27.748091, -98.2467799 27.748442, -98.2467449 27.748578, -98.2466399 27.748988, -98.2466059 27.749125, -98.2465649 27.749125, -98.2464419 27.749127, -98.2464019 27.749128, -98.2462229 27.749138, -98.2459529 27.749155, -98.2461409 27.749344, -98.2462679 27.749471, -98.2464499 27.74966, -98.2464219 27.749846, -98.2463679 27.750205, -98.2457849 27.75031, -98.2461659 27.750415, -98.2466009 27.750536, -98.2475449 27.750824, -98.2501459 27.751617))

from geophp.

BathoryPeter avatar BathoryPeter commented on June 10, 2024

@iamginpy: What was the tolerance parameter you have used in simplify() ? You get some error or an empty geometry?

from geophp.

iamginpy avatar iamginpy commented on June 10, 2024

$simplify = $polygon->simplify(0.01);
var_dump($simplify);

its giving me NULL result. I have already tried 1, 1.5 and 5. still null

from geophp.

BathoryPeter avatar BathoryPeter commented on June 10, 2024

Sorry, I forgot to mention that GeoPhp doesn't support simplify() natively, just with GEOS installed. See the docs: https://geophp.net/api.html

Please also note that if you are using geographical coordinates, the unit of tolerance parameter is in degrees. At 25˙ N its about one kilometer.

from geophp.

mishal avatar mishal commented on June 10, 2024

You can check my fork (https://github.com/mishal/GeoPHP) which would throw UnsupportedException for methods which require Geos php extension.

from geophp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.