By the way,

The shapefile that I am using for the Polygon geometry is a tiger line
shapefile.

Tiger lines use NAD83 CRS (4269).

i have found the following geotools page:

http://docs.codehaus.org/display/GEOTDOC/03+CoordinateReferenceSystem

Which says that conversion for WGS84 to cartesian is a very common
operation.

So I guess another way to do it is to transform my Lon/Lat points to
Cartesian values and just use those generated values to create a JTS
Coordinate object.  Then extract all Coordinates from the polygon geometry
and call Coordinate#equals2D() to find if there's a set of coordinates that
matches my point coordinate?

or is that exactly what I implemented below by using GeometryFactory?

thanks

Alessandro

On Mon, Mar 14, 2011 at 12:21 PM, Alessandro Ferrucci <
[email protected]> wrote:

> Andrea, thank you for the heads up about Axis order.
> OK so I think I have the correct implementation of how to do this, but I
> would like feedback from the community as to whether it's actually correct
> and any flaws it may have (go easy on me please, I'm a true noobie).
>
> Note:
> Shapefile is in GCS_North_American_1983 (I believe this should be SRID
> 4269).
> The lat/lon is a GPS coordinate (WGS84).
> I want to find out if the GPS coordinate is inside the Geometry from
> shapefile.  So I create a Geometry from coordinate and use Geometry.within
> to test if it's within shapefile Polygon.
>
> here is the code:
>
>
> //extract Polygon geometry from shapefile feature
> Geometry poly_geom= (Geometry) feature.getDefaultGeometry();
>
> //create coordinate from lon/lat
> Coordinate c = new Coordinate(-112.2808571, +40.5347509);
>
> //create GeometryFactory for SRID 4269
> GeometryFactory geom_factory = JTSFactoryFinder.getGeometryFactory(new
> Hints(Hints.JTS_SRID, 4269));
>
> //create point geometry using 4269 geometry factory
> Point lonlat_point = geom_factory.createPoint(c);
>
> if (lonlat_point.within(poly_geom)) {
>     logger.info("COORDINATE IS INSIDE POLYGON");
> }
> else {
>     logger.info("COORDINATE IS NOT INSIDE POLYGON");
> }
>
> I understand that if the point lies exactly on the boundary of the Polygon
> then it would return false, which is not what I want, however I am more
> concerned whether I have the fundementals of reprojecting my WGS84
> Coordinate to SRID:4269 and then finding if the geometry is within the other
> geometry, correctly.
>
> Thanks very much.
>
>
> On Mon, Mar 14, 2011 at 9:32 AM, Andrea Aime <[email protected]
> > wrote:
>
>> On Mon, Mar 14, 2011 at 1:49 PM, Alessandro Ferrucci
>> <[email protected]> wrote:
>> > Thanks very much for the info, I have another question.
>> >
>> > I believe these points were captured with a GPS.  Is the standard GPS
>> > Coordinate projection WGS84?
>>
>> Yep. You still have to beware of axis order though, all shapefiles I
>> ever encountered
>> and most spatial data storage systems in general work in lon/lat
>> order, not lat/lon
>>
>> Cheers
>> Andrea
>>
>> --
>> -------------------------------------------------------
>> Ing. Andrea Aime
>> GeoSolutions S.A.S.
>> Tech lead
>>
>> Via Poggio alle Viti 1187
>> 55054  Massarosa (LU)
>> Italy
>>
>> phone: <%2B39%200584%20962313> 
>> <%2B39%200584%20962313><%2B39%200584%20962313>+39
>> 0584 962313
>> fax:       <%2B39%200584%20962313> 
>> <%2B39%200584%20962313><%2B39%200584%20962313>+39
>> 0584 962313
>> mob:     <%2B39%20333%208128928> 
>> <%2B39%20333%208128928><%2B39%20333%208128928>+39
>> 333 8128928
>>
>> http://www.geo-solutions.it
>> http://geo-solutions.blogspot.com/
>> http://www.youtube.com/user/GeoSolutionsIT
>> http://www.linkedin.com/in/andreaaime
>> http://twitter.com/geowolf
>>
>> -------------------------------------------------------
>>
>
>
>
> --
> Signed,
> Alessandro Ferrucci
>



-- 
Signed,
Alessandro Ferrucci
------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to