Is there a way to search polygons which are inside another polygon with elasticsearch?
If not, is it possible with Solr or another system?
Totally possible on Elasticsearch:
http://elasticsearch-users.115913.n3.nabble.com/Can-I-use-geo-polygon-filter-to-retrieve-hits-based-on-polygon-fields-td4044079.html
I'm just looking into implementing it myself, my only worry is performance on a high traffic site so we'll see what happens.
As this post was a while ago it would be interesting to know what you ended up doing...
With Solr 4.3 it just became possible; I just finished working on it a couple weeks ago and I'm pretty excited about it. To learn how to use the new Solr 4 spatial field, see: http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4 What's new is that you can now use the "IsWithin" and "Contains" predicates; there's "IsDisjointTo" too. Based on your question, it's not clear to me which of those you want. Imagine a 3-part sentence in which the first/left part is your index data, then there's the spatial predicate, then there's your query shape. So if you want to search for indexed shapes that are WITHIN your query shape, then use "IsWithin". I was just about to update the wiki to show these predicates.
Pretty sure it's not possible with ES.
With Solr + some plugins I think it's possible, but haven't tried it myself.
Have a look at https://github.com/spatial4j/spatial4j
Shape classes that are geospatially1 aware Shapes: Point, Rectangle,
Circle, Polygon (via JTS) shape intersection logic, yielding:
disjoint, contains, within, intersects bounding box area calculation
It seems spatial4J is already included in Solr. See David Smiley's response (author of Spatial4J and commiter to Solr) in the below link
How to install spatial4j into solr4
Related
Here is my problem which I am trying to solve since one complete year. With no success till end of the year. I have to seek help and a concrete solutions from the stackoverflow experts.
My problem statement:
I have been working with some design patterns which I want to trace if eulerian path exist(as shown in below gifs), programmatically. Below are the patterns and the way I wanna draw them(gifs).
What I wanna achieve:
Give the design pattern images as input. I want trace the design pattern image in a single stroke as shown in the gifs(gifs animations are just examples of how the patterns is drawn in single stroke). Once I get the x and y coordinates of the image in single stroke fashion(eulerian path). I will feed those coordinates to my program to just trace those coordinates.
Thing to be noted in the animation:
1) basically its an undetected graph (the nodes being the vertices of your shapes, the edges if exists being the strokes between 2 vertices). (eulerian path)
Here are the 15 unique shapes which I used to build the patterns with:
I have more then 400 patterns(3 patterns already shown below) and till now I am not able to find a generic solution for this. I have manually got the x y coordinates of the patterns and placed it in sequence. But that is not at all scalable.
How to trace the patterns such that each node is visited only once ?:
1st kind of pattern and the way it should be drawn:
2nd kind of pattern and the way it should be drawn:
3rd kind of pattern and the way it should be drawn:
Perhaps you can look into the traveling salesman problem if your still struggling with the above. TSP visits cities only once. And if in your case each node is a crossing for your strike-through then this might help.
Check here for the python code to look at. I've checked and the print statement looks nice and structured. Well done cMinor!
Edit based on discussion: file 1, file2, file3.
I've been attempting to export boundary information from an OSM file. My process is nearly there however I have an issue with the polygon I'm generating drawing random lines.
I would appreciate some insight on where I may be going wrong.
Step 1: Export the OSM data into XML
osmfilter -v greater-london-latest.osm --keep="boundary= admin_level= place=" > b.txt
Step 2: Run a script to process the XML.
cycle each relation node
load the member ways
load the nodes from each specified way
record the lat/lon and build a poly set
This produces a series of lat/lon which when I build them as a polygon give the correct overall shape I'm looking for. However, there are issues with the connecting lines I assume..
My polygon output
I'm actually looking for this, which is similar but Im obviously missing something.
Actual Poly Im looking to generate
Again, thanks for any help.
Ways in relations are not necessarily sorted. See answers to this question on how to sort ways, especially the answer by user geocodezip.
Alternatively you can make use of various tools/libraries to do the sorting for you. Unfortunately I can't point you directly to one but there are various tools capable of sorting relation members, including the OSM website itself, JOSM, overpass turbo (I guess), some JS stuff, [...].
Maybe some other user can help out with pointing to some good examples?
I am developing a location-based application in which I need to get nearby location name of any geopoint selected by user. I'm using Google Places API which is working fine for me.
Only problem is the service returns null for geopoints in water. Is there any way that I can retrieve nearby locations for a geopoint in water or ocean?
AFAIK the API has no way to do that.
So, you've got two options, in order of the effort it takes:
When user taps water just throw a dialog saying "Please select a
point on land". Next to no effort and will slightly annoy the user.
Try to find the closest land geopoint yourself and use it to run the API request on
(instead of the original point). Below are some ideas on that.
A good approach can be based on this answer: basically you can get a KML file with land polygons. For performance reasons, you can simplify the polygons to the extent that makes sense for your zoom levels. Now if your point is in one of those polygons -- it's sea. And you can simply iterate over all polygon edges and pick the one that's closest to your point, then pick a point on it - again closest to your point - and do one little epsilon-sized step towards the outside of the polygon to get a land point you can do a geocode request on. Also, the original author suggests you can use Haversine formula to determine neares land point -- I'm not really familiar with the appliance of that one.
The downside is, you have to deal with KML, iterate over a lot of polygons and optimize them (and lose precision doing that, in addition to possible differences between marineregions.org data and Google Places data)
Another cool trick you could try is using Sobel Filter [edge detection] on the visible map fragment to determine where coastline is (although you will get some false positives there), then trace it (as in raster->vector) to get some points and edges to calculate the closest land position with, in a manner similar to the former approach. Here's a clumsy drawing of the idea
For Sobel edge detection, consider GPUImage lib -- they have the filter implemented and it's probably going to work crazy fast since the lib does all the calculations on GPU.
UPD Turns out there's also a service called Koordinates that has coastline data available, check the answer here
Using Rails and Googlemaps V3, I'm looking some advice (before i head off down the wrong path) for the best approach to build the functionality to:
1) draw a polygon that describes a geographical area
2) capture and save the polygon data to the db (postgres)
3) make a query that will tell me if a point is inside the polygon or not
As far as i can see from examples that are out there - the polygon drawing bit is fairly doable but i'm not clear how to capture that data, and in which format i should save it (i see postgres has a polygon data type...). Also for the query, i'm not sure how to go about making that happen - does postgres have any magic that can make this happen (we're using heroku).
Any advice or pointers would be greatly appreciated!
Thanks!
In general your options depend in part on scale. If this is a flat, plane map, the best approach would be a polygon and point approach. This would work best for things like city maps.
For a global map you probably want to use PostGIS's geometry and geography types since they are more flexible.
my Application is given a list of Geocorrdinates and now I have to determine which of those Coordinates are inside a defined Area. For example the Search would definiton would be: Show me all Areas where 100 Coordinates are in an Area of 1km^2. So I have to find out which of these coordinates are together in Areas of 1km^2 and more than 100.
But that seems to be a hard Job for my understanding of geocoordinates and I hope someone can help me with that.
The Latitude coordinates are consistent and Distance between two degrees is 111km. For example the Distance between N50,985° and N50,995° is 1,11km. The Distance between 2 Longtitude Coordinates is not so easy and depends on the Latitude coordinate.
But to be honest, I really don't know how to start.
Does someone have an Idea and can help me?
Thank you
twickl
what you need is a geospatial database, I'd recommend PostgreSQL with PostGIS. It provides the function you need to calculate this kind of stuff. Also search for good tutorials about it. An example is a radius search like "give me all McDonalds in a radius of 10km where I live"
If the problem with having a database is simply that you don't want to host it (or pay for someone to host it) then I recommend Fusion Tables.
I don't know if it supports exactly the functionality you are looking for, however I suppose you could select a random point and do a count of everything within range of that point.
I think that what you are talking could be quite a cpu intensive task (depending on how accurate you want it to be). Not something I would personally try and unload onto a portable device.