Re: [Jts-topo-suite-user] Create point geometry from lat/lon
Brought to you by:
dr_jts
From: Martin D. <mtn...@gm...> - 2011-03-14 15:59:32
|
If you have a Point geometry P and a polygon geometry G then yes, you can check if the point is contained in the polygon by using: P.within(G) or G.contains(P) Be aware that if the point lies exactly on the boundary of the Polygon these will return false - which is probably not what you want. To return true in this case instead, use: P.coveredBy(G) or G.covers(P) This will only work if both geometries are in the same coordinate system. And it doesn't work very well for geodetic (spheriodal or geographic) coordinate systems, since JTS assumes that the edges of Polygons are linear (which obviously is not the case on the spheroid). You can reduce the error somewhat by densifying the Polygon edges *along a great circle arc*. But this functionality is not currently provided in JTS. Or you can reproject your data to a planar coordinate system and compute there. This works as long as geometries are not too large. There have been discussions about extending JTS to properly handle geodetic data. You can read about this here: https://docs.google.com/document/pub?id=12RqBN16nKzDFgMqEMczAuHjx-dqCGR_B2YVkB3W-aQI But so far no code has been cut. Martin On Mon, Mar 14, 2011 at 5:55 AM, Alessandro Ferrucci < ale...@gm...> wrote: > Hello Martin thanks very much for the info. > > I have another question and this is just out of curiosity. > > Would creating a Geometry object out of the Coordinates and testing if the > point coordinates is within the shapefile polygon using > > pointGeom.within(shapeGeom) > > would this work? > > do I have to do something extra to the pointGeom (probably reprojecting to > the same coordinate system as the shapefile geometry?) > > > |