Hello,


I have the need to find if a Point resides inside a MultiPolygon. Where the 
MultiPolygon is from a Shapefile and the point is Primitive.



I wrote code based off of the filter query tutorial 
(http://docs.geotools.org/latest/tutorials/filter/query.html) but I keep 
receiving 0 (zero) results. If someone could point me in the right direction I 
would appreciate it. My code follows below:



Chad Hutchins

Meteorologist

Naval Research Laboratory

Marine Meteorology Division

Monterey, CA





       /**

       *

        * This method tells you what COCOM your point is in.

       *

        * @param lat (String)

       * @param lon (String

       * @return the COCOM Name

       */

       public String getCOCOMfromLatLon(String lat, String lon) {



              //Holder for COCOM once found

              String command = null;



              //To point

              DirectPosition here = positionFactory.createDirectPosition(new 
double[] { Double.parseDouble(lon), Double.parseDouble(lat) });



              Point point = primitiveFactory.createPoint(here);



              //System.out.println("POINT TEST::: " + 
point.getRepresentativePoint().getCoordinate().toString());



              FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);



              //Schema for finding local name

              SimpleFeatureType type = source.getSchema();



              System.out.println("GEO DESC:: " + 
type.getGeometryDescriptor().getLocalName());



              Filter filter = 
ff.within(ff.property(type.getGeometryDescriptor().getLocalName()), 
ff.literal(point));



              try {

                     SimpleFeatureCollection results = 
source.getFeatures(filter);



                     //System.out.println("RESULTS SIZE::: " + results.size());

                     //System.out.println("SIZE CHECK::: " + 
source.getFeatures().size());



                     //We should only find one!

                     if (results.size() > 1) {

                           throw new Exception("Too Many Results for COCOM 
Search");



                     } else if (results.size() == 0) {

                           System.err.println("DID NOT FIND A COCOM");



                     } else {

                           FeatureIterator<SimpleFeature> i = 
results.features();



                           SimpleFeature f = i.next();



                           command = f.getAttribute("COMMAND").toString();



                     }



              } catch (IOException e) {

                     // TODO Auto-generated catch block

                     e.printStackTrace();

              } catch (Exception e) {

                     // TODO Auto-generated catch block

                     e.printStackTrace();

              }



              return command;



       }

------------------------------------------------------------------------------
Own the Future-Intel&reg; Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest.
Compete for recognition, cash, and the chance to get your game 
on Steam. $5K grand prize plus 10 genre and skill prizes. 
Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to