Thanks Ian! That should help me a lot! I've already tried to implement that code, but I'm having some problems with it... Every time I run it, i get a NullPointerException...
Here are some details about what I've done: code: http://pastebin.com/fM7DNDfw sample data: http://pastebin.com/7ynCykXc (this is data taken from the file I have) exception details: http://pastebin.com/MTj9YjjH I don't know if it has something to do with it, but the System.out which prints the filter prints something like "POLYGON(.....", and in the data I have, the geometry field has somthing like "MULTILINESTRING(....". Could this be the problem? If so, how can I get around it? Thanks and best regards João Norim PS: I think the only thing I forgot in the pastebin with the code was the geometry factory I'm using. I'm using this one: GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); Date: Thu, 29 Oct 2015 15:18:51 +0000 Subject: Re: [Geotools-gt2-users] Doubts about geotools usage. University project. From: ijtur...@gmail.com To: norim...@hotmail.com CC: geotools-gt2-users@lists.sourceforge.net You could do something like this: public List<SimpleFeature> search(Point p) { List<SimpleFeature> ret = new ArrayList<>(); Coordinate[] coords = new Coordinate[5]; double tol = 0.001; double left = p.getX() - tol; double right = p.getX() + tol; double bot = p.getY() - tol; double top = p.getY() + tol; coords[0] = coords[4] = new Coordinate(left, bot); coords[1] = new Coordinate(right, bot); coords[2] = new Coordinate(right, top); coords[3] = new Coordinate(left, top); Polygon poly = geometryFactory.createPolygon(coords); Intersects filter = FF.intersects(FF.literal(poly), FF.property(geomName)); System.out.println(filter); try { SimpleFeatureCollection features = featureSource.getFeatures(filter); ret.addAll(DataUtilities.list(features)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ret; } Note the need to make the point "bigger" otherwise it probably won't ever hit a line. Ian On 29 October 2015 at 10:16, João Bandeira <norim...@hotmail.com> wrote: Hi! My name is João, I'm from Portugal, and I'm a Software and Computer Engineering student at FEUP. I'm contacting you about GeoTools. I'm contacting users through the email list as a suggestion given by Andrea, one of the geotools developers. I'm currently developing a project for college where I have to interpret a map of the rivers in my country. I have access to a file with info of all the rivers. It's a file with the extension .shp, and I was already able to open it using the geotools tools. I was able to open the map in the swing interface of geotools, and see all the rivers, and also see information of each river by clicking it. After this, I was able, with a few lines of code, to search info about a river by its name: I opened the file, and made a query with a filter applied to one of the fields (designation of the river), and it will find all the rivers which contain a given string in its designation. When I wrote this code, I noticed that for each river, there is some geometric(?) information about them, a list of coordinates. As I have no knowledge about this type of files and its structure, I really don't know how to interpret those coordinates, and I really needed some way to do that. The functionality that I need to implement is, given a pair of coordinates (latitude and longitude), check if it belongs to any river in the file, and return info about it. I know that it should be possible because using the swing interface, and clicking the river, it returns info about it, so I think that somehow the program receives coordinates about the place I clicked, and searches the file for a river containing those coordinates. Am I right? If so, and if possible, what I needed to know is how to do that... My plan was to reverse engineer the code with eclema for eclipse, but I couldn't import all the source code to my project, so I didn't succeed, that's why I'm contacting you. Probably what I want to do is simple, and a few guidelines from someone who is familiarized with the project will suffice. My main problem is how to convert latitude and longitude to the coordinate system used in the file I have, and also match a pair of coordinates to the info in the file (to check if they belong to any river). If it helps, here is the file I'm working with: http://1drv.ms/1SaccYG Sorry for bothering you with this, but you're probably my last resource, as I've been struggling with this for the last week, with no luck... Thanks and best regards, João Norim ------------------------------------------------------------------------------ _______________________________________________ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users -- Ian Turton
------------------------------------------------------------------------------
_______________________________________________ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users