## geotools-gt2-users

 [Geotools-gt2-users] WGS84 Point in Polygon From: Duane Zamrok - 2010-05-19 17:52:55 Attachments: Message as HTML ```Good afternoon everyone (at least here it is), I'm working on a project that monitors an incoming data stream for geospatial locations (longitude/latitude) that fall inside of a region of interest. I'm new to geotools and although I've read a decent amount of the documentation and talked to a few people, I can't seem to determine a reliable way to do this. So my question to the masses is as follows. If you had both a longitude/latitude position and a set of longitude/latitude positions defining a closed linear ring, how would you go about determining if the position was inside the polygon using the geotools libraries? Thank you in advance -Duane ```
 Re: [Geotools-gt2-users] WGS84 Point in Polygon From: Ian Turton - 2010-05-19 18:02:07 ```On Wed, May 19, 2010 at 1:52 PM, Duane Zamrok wrote: > Good afternoon everyone (at least here it is), > >                 I’m working on a project that monitors an incoming data > stream for geospatial locations (longitude/latitude) that fall inside of a > region of interest. I’m new to geotools and although I’ve read a decent > amount of the documentation and talked to a few people, I can’t seem to > determine a reliable way to do this. So my question to the masses is as > follows. If you had both a longitude/latitude position and a set of > longitude/latitude positions defining a closed linear ring, how would you go > about determining if the position was inside the polygon using the geotools > libraries? > > You need a Geometry filter, specifically a within feature which can compare your point to the polygon. See the example on http://docs.codehaus.org/display/GEOTDOC/Filter+Examples (at the end). Ian -- Ian Turton ```
 Re: [Geotools-gt2-users] WGS84 Point in Polygon From: Duane Zamrok - 2010-05-19 18:19:36 ```Thank you for the quick response, but I think you may have misunderstood my question. The link that you sent me appears to deal with querying a database for items whose location is within the bounds of a bounding box. However, I'm not working with a database and my problem is much more closely related to what coordinate system I should be using to perform the calculations. From what I've read of JTS it is strictly a Cartesian geometry library. It is unable to handle the transitions from -180 to 180 on the longitude axis or the transition from -90 to 90 on the latitude axis. This prompts me to believe that I must somehow transform my coordinates before creating the polygon and doing the computation. However, I'm not sure what coordinate system I should be using to maintain accuracy. Thanks -Duane -----Original Message----- From: Ian Turton [mailto:ijturton@...] Sent: Wednesday, May 19, 2010 2:02 PM To: Duane Zamrok Cc: geotools-gt2-users@... Subject: Re: [Geotools-gt2-users] WGS84 Point in Polygon On Wed, May 19, 2010 at 1:52 PM, Duane Zamrok wrote: > Good afternoon everyone (at least here it is), > > I'm working on a project that monitors an incoming data > stream for geospatial locations (longitude/latitude) that fall inside of a > region of interest. I'm new to geotools and although I've read a decent > amount of the documentation and talked to a few people, I can't seem to > determine a reliable way to do this. So my question to the masses is as > follows. If you had both a longitude/latitude position and a set of > longitude/latitude positions defining a closed linear ring, how would you go > about determining if the position was inside the polygon using the geotools > libraries? > > You need a Geometry filter, specifically a within feature which can compare your point to the polygon. See the example on http://docs.codehaus.org/display/GEOTDOC/Filter+Examples (at the end). Ian -- Ian Turton ```
 Re: [Geotools-gt2-users] WGS84 Point in Polygon From: Ian Turton - 2010-05-19 18:25:33 ```On Wed, May 19, 2010 at 2:19 PM, Duane Zamrok wrote: > Thank you for the quick response, but I think you may have misunderstood my question. The link that you sent me appears to deal with querying a database for items whose location is within the bounds of a bounding box. The last example contains the line polyCheck=ff.not(ff.disjoint(ff.property("the_geom"),ff.literal( feature.getPrimaryGeometry() ))); which should be what you want. The joy of GeoTools is that it abstracts the datastore you are using away from your code so it won't matter what store you use, the code at the bottom of that page will work on it. >However, I'm not working with a database and my problem is much more closely related to what coordinate system I should be using to perform the calculations. From what I've read of JTS it is strictly a Cartesian geometry library. It is unable to handle the transitions from -180 to 180 on the longitude axis or the transition from -90 to 90 on the latitude axis. This prompts me to believe that I must somehow transform my coordinates before creating the polygon and doing the computation. However, I'm not sure what coordinate system I should be using to maintain accuracy. > Someone else may be able to help you with that, I don't know if our filters handle projections well (at all?). Ian -- Ian Turton ```
 Re: [Geotools-gt2-users] WGS84 Point in Polygon From: Duane Zamrok - 2010-05-20 15:12:56 ```I've played around with the Filters some more (as was suggested), and I still can't seem to find what I'm looking for. If you'll please excuse my use of a list, I think it will be helpful to better outline my problem. Problem: I start out with a polygon defined as a closed line string of longitude latitude points. After starting, I begin to receive longitude/latitude coordinates, one at a time through web service calls. I want to determine if the longitude/latitudes I'm receiving are located inside of the polygon I started with. Given: JTS is a 2.5D Cartesian geometry computation library. It is not capable of understanding that 180 lies between -170 and 170. Need: (I think) A 2D Cartesian coordinate system to represent my points in. It seems to me that while this might not be an easy problem, it is likely a classic problem. I've talked to people who suggested NED, but given that my points can be located anywhere on the earth I understand that NED's accuracy is extremely skewed given a large distance. (it's local horizon isn't it?). I appreciate all the help I've received already and thank you in advance for any more direction you might provide me. Thank You -Duane -----Original Message----- From: Ian Turton [mailto:ijturton@...] Sent: Wednesday, May 19, 2010 2:25 PM To: Duane Zamrok Cc: geotools-gt2-users@... Subject: Re: [Geotools-gt2-users] WGS84 Point in Polygon On Wed, May 19, 2010 at 2:19 PM, Duane Zamrok wrote: > Thank you for the quick response, but I think you may have misunderstood my question. The link that you sent me appears to deal with querying a database for items whose location is within the bounds of a bounding box. The last example contains the line polyCheck=ff.not(ff.disjoint(ff.property("the_geom"),ff.literal( feature.getPrimaryGeometry() ))); which should be what you want. The joy of GeoTools is that it abstracts the datastore you are using away from your code so it won't matter what store you use, the code at the bottom of that page will work on it. >However, I'm not working with a database and my problem is much more closely related to what coordinate system I should be using to perform the calculations. From what I've read of JTS it is strictly a Cartesian geometry library. It is unable to handle the transitions from -180 to 180 on the longitude axis or the transition from -90 to 90 on the latitude axis. This prompts me to believe that I must somehow transform my coordinates before creating the polygon and doing the computation. However, I'm not sure what coordinate system I should be using to maintain accuracy. > Someone else may be able to help you with that, I don't know if our filters handle projections well (at all?). Ian -- Ian Turton ```
 Re: [Geotools-gt2-users] WGS84 Point in Polygon From: Michael Bedward - 2010-05-21 01:17:32 ```Hello Duane, > JTS is a 2.5D Cartesian geometry computation library. It is not capable of understanding > that 180 lies between -170 and 170. Perhaps just normalize the incoming coordinates to [0, 360) then you can test them against your polygon (with its vertices normalized in the same manner). Michael ```
 Re: [Geotools-gt2-users] WGS84 Point in Polygon From: Duane Zamrok - 2010-05-21 13:51:58 ```Thanks Michael, I recently came to the same thought myself, but it doesn't seem to address the circular nature (IE 360 lies between 10 and 340 traveling west). I'm starting to think that I'm approaching this problem from the wrong direction entirely, but not quite sure yet. I'm really beating myself up over this because it seems like such a simple problem, but is clearly the spawn of a demon. Thanks for the suggestion -Duane -----Original Message----- From: Michael Bedward [mailto:michael.bedward@...] Sent: Thursday, May 20, 2010 9:17 PM To: Duane Zamrok Cc: geotools-gt2-users@... Subject: Re: [Geotools-gt2-users] WGS84 Point in Polygon Hello Duane, > JTS is a 2.5D Cartesian geometry computation library. It is not capable of understanding > that 180 lies between -170 and 170. Perhaps just normalize the incoming coordinates to [0, 360) then you can test them against your polygon (with its vertices normalized in the same manner). Michael ```
 Re: [Geotools-gt2-users] WGS84 Point in Polygon From: benjholla - 2010-07-28 23:20:42 ```Hello, I have been slamming my head against the wall for the past week trying to do exactly the same thing. I want to generate random points within the United States, I planned on using the polygon features of JTS to do this operation, but I'm confused how to create an accurate polygon from lat/lng points. Did you ever find a solution to this problem? I would greatly appreciate any help. I can't believe this is so hard, it seems like such a common problem that many applications should have solved already. I tried doing something like below, but there is no transformatin for this. CoordinateReferenceSystem sourceCRS = org.geotools.referencing.crs.DefaultGeographicCRS.WGS84; CoordinateReferenceSystem targetCRS = org.geotools.referencing.crs.DefaultEngineeringCRS.CARTESIAN_2D; MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS); Geometry targetGeometry = JTS.transform(srcGeomotry, transform); -- View this message in context: http://osgeo-org.1803224.n2.nabble.com/WGS84-Point-in-Polygon-tp5076094p5346547.html Sent from the geotools-gt2-users mailing list archive at Nabble.com. ```
 Re: [Geotools-gt2-users] WGS84 Point in Polygon From: Duane Zamrok - 2010-07-29 15:33:49 ```Yea, there are a number of CRS in geotools that exist without transformations. I spent a lot of time working on this problem, and although I'm sure it is not the best solution, the only way I really found to do it was to use ENU coordinates. I made a post about doing the conversion, but have not actually had time to add it to the library. You will need to do this conversion yourself. Look up "[Geotools-gt2-users] Longitude Latitude to East North Up" to see the code that transforms from lat long to ENU, and then use the JTS polygons to do the testing on your ENU coordinates. Fair warning, ENU is a local horizon and as such is most accurate close to the origin. -Duane -----Original Message----- From: benjholla [mailto:benjholla@...] Sent: Wednesday, July 28, 2010 7:21 PM To: geotools-gt2-users@... Subject: Re: [Geotools-gt2-users] WGS84 Point in Polygon Hello, I have been slamming my head against the wall for the past week trying to do exactly the same thing. I want to generate random points within the United States, I planned on using the polygon features of JTS to do this operation, but I'm confused how to create an accurate polygon from lat/lng points. Did you ever find a solution to this problem? I would greatly appreciate any help. I can't believe this is so hard, it seems like such a common problem that many applications should have solved already. I tried doing something like below, but there is no transformatin for this. CoordinateReferenceSystem sourceCRS = org.geotools.referencing.crs.DefaultGeographicCRS.WGS84; CoordinateReferenceSystem targetCRS = org.geotools.referencing.crs.DefaultEngineeringCRS.CARTESIAN_2D; MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS); Geometry targetGeometry = JTS.transform(srcGeomotry, transform); -- View this message in context: http://osgeo-org.1803224.n2.nabble.com/WGS84-Point-in-Polygon-tp5076094p5346547.html Sent from the geotools-gt2-users mailing list archive at Nabble.com. ------------------------------------------------------------------------------ The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of \$1 Million in cash or HP Products. Visit us here for more details: http://p.sf.net/sfu/dev2dev-palm _______________________________________________ Geotools-gt2-users mailing list Geotools-gt2-users@... https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users ```