For the internal information system, it became necessary to work with information tied to ordinary residential buildings.

To display a card is trivial - every first is able. In particular, a house map has been already made in half an hour, based on OpenStreetMap / Leaflet, where every house for which there is a geo-tagged entry in the database is marked with a marker.

The problem arose in reverse geocoding - how to make it possible for the user to click on the polygon-building on the map and the address of this object was recognized? Those. a “new” (for the company) house appears, which must be added to the base. The user goes, clicks on the house, a panel appears adding entries for the house at this address. If it clicks not on the house, but on something else, nothing happens (because there is no object in this place).

The quick crutch was the use of Nominatim, but the results of reverse geolocation on the coordinates leave much to be desired, and the result is not so hot. I’m poking in the wasteland outside the city, I’m getting an address somewhere in the city, and it’s not even clear where this is (the landfill doesn’t return). I would like to get an answer or “I don’t know anything here” or “there is a building object, nobody has already assigned an address to it on OSM (not bad, we'll write it ourselves and send it to OSM), but in general it’s a polygon about 4 vertices, coordinates are attached.” In the emphasis I can not find anything more or less ready in the pile of fragmented documentation.

Of course, there is an option - download the OSM dump, stuff PostgIS with PostGIS, and, after reading some documentation, make your own geocoder. But for sure I'm not the first with such desires, and something is already more ready than the creation of the whole bike from scratch.

Scale - a small town, roughly - up to 10,000 buildings. Up to the point that you can cut into squares (roughly, 10x10), but do all the client-side. Requests for geocoding - up to, probably, a couple of dozen on a particularly productive day, that is, mere trifles.

Yes, Google Maps, Yandex.Maps, 2GIS - thanks, does not fit, all of them have a license agreement that requires a) use for a site open for all, not an internal corporate admin panel and b) severely limits the ability to use data received from the geocoder ( consider vendor lock-in).

  • one
    As it turned out, it is trivial to tear out all the houses and present them as a JSON document: https://gist.github.com/4154170 But the metadata of houses on OSM is scarce, and writing a solution to the problem “determine the occurrence of a polygon (house) in another polygon (city) ", Though not difficult, but very lazy. As well as I do not really want to touch the combat PostgreSQL, delivering there PostGIS. Therefore, I am still waiting for the advice of the wise, suddenly what is more ready to eat. - drdaeman Nov.
  • If you do not really want to touch combat Postgres (which is quite normal), get a test. - shoorick

4 answers 4

Also there was a similar task. But we originally had PostgreSQL deployed with PostGIS for storing geo-data.

If you need to get a house by coordinate for a large number of coordinates, it is better to simply perform queries directly to the database. Find a hit point in the geometry and then choose the house is not difficult.

If you need to get a house from a client (web browser) when you click the map, OpenLayers and GeoServer allow you to get the necessary information by calling WMSGetFeatureInfo (). Only you will need to filter the output and select only at home.

At one time, I looked at various systems for the reverse geocodink, but for my tasks it turned out to be much easier in all plans to use the approach described above.

In your case, your geocoder, as you put it, will be reduced to writing a couple of queries to the database. So I recommend setting up PostGIS, uploading only your city there and periodically updating it.

By the way, it is not necessary to edit combat PostgreSQL. It would be even better if a separate database was configured for geo-data.

    About six months ago I had to solve the same problem. Finished solutions could not be found. I had to do it myself, starting with solving the inverse problem: from receiving from OSM and saving in our database of polygons for all addresses in the city. Further, these polygons were loaded into memory in the form of an R-tree . More precisely, not the polygons themselves, but the rectangles into which they are inscribed. A search on such a tree allows you to effectively find these rectangles, after which you need to check that you hit directly into the polygon.

      Here is the solution, looking for a provider to choose from (bing, google, nokia, osm):

      L.Control.GeoSearch - search for address and zoom to its location https://github.com/smeijer/L.GeoSearch