NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

Hello, I downloaded an OSM file from my area (Italy islands) to process it with Java and present an application to my organization. The purpose is, given a point on the map where a criminal activity is in progress, to find in the vicinity (e.g. 500 meters or 1 Km) all the POIs that represent sensitive targets (banks, schools, jewelers, etc.) that can become secondary targets for crimes. For now, I need this information in data format and not as a map. The problem is that in the OSM file I have the city field is often null and from the geographic coordinates of the city limits I cannot make an initial list of all the POIs present. At this point I thought about changing cities hoping that there is one that has a more complete OSM file.

asked 10 May '21, 05:07

Lorenzopandolfo's gravatar image

accept rate: 0%

Which "city field" is null? Is this about the addr:city tag?

(10 May '21, 08:20) scai ♦

exactly I am referring to that tag.

(10 May '21, 08:38) Lorenzopandolfo

What tool, or library, are you using to read the OSM file ? You probably can search around a point and don't care about the city limits.

If you need to reduce the size of the file, I pretty sure osmium, or osmconvert, can crop an OSM file based on a geoJSON, which you could get from overpass-turbo.


(10 May '21, 10:03) H_mlet

You cannot count on the addr:city field being set. You have to work, as you say, with the geographic coordinates of the city boundary which will often be present in OSM. If you load the OSM data into a PostgreSQL database with osm2pgsql, creating the list of POIs in a city is trivial. First, find the relation ID of the city,

select osm_id,name 
from planet_osm_polygon 
where boundary='administrative' and admin_level=8;

(Add an "and name like '%something%' to reduce the list to certain names only. In some countries cities might have a different admin_level; sometimes this also depends on the city size. Check the boundary=administrative wiki page for details.)

Once you have the ID of the boundary (let's say it was -41485 which is the city of Rome), you can do something like

select * from planet_osm_point p,     
   planet_osm_polygon q
where and st_contains(q.way, p.way);

You could also add something like "and amenity in ('bank','post_office', ...)" to that query to limit the results.

permanent link

answered 10 May '21, 09:43

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
accept rate: 23%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 10 May '21, 05:07

question was seen: 998 times

last updated: 10 May '21, 10:03

NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum