0

Imagine I have a map shape file (.shp) or osm xml, I'm able to see different kind of data from different layers in GIS oriented programs, e.g. ArcGIS, QGIS etc. But how can I get this info programmatically? Is there a specific library for that? What I'm really looking for is a some kind of method getMapData(longitude, latitude) to get landscape/terrain info (e.g. forest, river, city, highway) in specified location

Thanks in advance for your answers!

kmityak
  • 461
  • 5
  • 11

3 Answers3

1

Shapefiles or an osm xml file are just containers that hold geometric shapes. There are plenty of software libraries out there that let you read these files and extract the data. I would recommend looking at GDAL/OGR as a starting point.

A method like getMapData(longitude, latitude) is essentially a search/query function. You need to be a little more specific too, do you want geometries that contain the point, are within a distance of a point, etc?

You could find the map data using a brute force algorithm

for shape in shapefile:
    if shape.contains(query_point):
        return shape

Or you can use more advanced algorithms/data structures such as RTrees, KDTrees, QuadTrees, etc. The easiest way to get start with querying map data is to load it into a spatial database. I would recommending investigating PostgreSQL+PostGIS and SpatiaLite

Charles
  • 1,820
  • 13
  • 16
  • Thanks for your advices. Actually I'm going to solve some scientific task, that requires such kind of info to build an internal database of obstacles (It will also include weather and elevation information). I'd like to create a grid of a specific area, each cell in a grid will store some map object data, which will contain info about geo-coordinates, landscape type, weather, elevation and so on. Could you please tell, are those programs you proposed can help me in achieving my goal? – kmityak Dec 18 '11 at 19:56
  • Yes those programs are a good start, but it sounds let you need to better define your problem. – Charles Dec 20 '11 at 22:08
1

It still depends what you want to achieve whether you are better off using raster or vector data.

If your are using your grid to subdivide an area as an array of containers for geographic features, then stick with vector data. To do this, I would create a polygon grid file and intersect it with each of your data layers. You can then add an ID field that represents the cell's location in the array (and hence it's relative position to a known lat/long coordinate - let's say lower left). Alternatively you can use spatial queries to access your data by selecting a polygon in your vector grid file and then finding all the features in your other file that are contained by it.

OTOH, if you want to do some multi-feature analysis based on presence/abscence then you may be better going down the route of raster analysis. My gut feeling from what you have said is that this is what you are trying to achieve but I am still not 100% sure. You would handle this by creating a set of boolean rasters of a suitable resolution and then performing maths operations on the set (add, subtract, average etc - depending on what questions your are asking).

Let's say you are looking at animal migration. Let's say your model assumes that streams, hedges and towns are all obstacles to migration but roads only reduce the chance of an area being crossed. So you convert your obstacles to a value of '1' and NoData to '0' in each case, except roads where you decide to set the value to 0.5. You can then add all your rasters together in one big stack and predict migration routes.

Ok that's a simplistic example but perhaps you can see why we need EVEN more information on what you are wanting to do.

MappaGnosis
  • 1,179
  • 1
  • 11
  • 25
  • Well, your example is a very close to my task in general. What I'm going to solve is a distribution of forest fire, but in this case I'll need to get info about obstacles as well, and of course about forests. Why I don't want to use raster, because with vector data my model will be more flexible to some changes in accuracy or in map at all, and I won't have to reconvert vector to raster again. That's it. – kmityak Dec 22 '11 at 11:23
  • This is a classic GIS application and there are lots of examples you may find useful (e.g. http://www.esri.com/library/brochures/pdfs/wildland-fire-suppression.pdf ). – MappaGnosis Dec 22 '11 at 18:41
  • {sorry pressed 'ENTER too soon!} Vectors are great for discrete information and rasters are better for continuous data (e.g. rainfall, windspeed and the combustability of areas at the fire front). Your limits of accuracy are only relevant in relation to the distance the fire can 'jump'. So, raster calculations at a suitable resolution are MUCH easier and perfectly acceptable. Vector data might complicate the calculations considerably for questionable benefits in the results. Most other forest fire models I know of use raster analysis and ESRI has some great examples. – MappaGnosis Dec 22 '11 at 19:15
0

You may also like to look at Spatialite and/or PostGIS which are two spatial enabled databses that you could use separately or in conjunction with GDAL/OGR.

I must echo Charles' request that you explain your use-case in more detail because the actual implementation will depend greatly on exactly what you are wanting to achieve. My reading of this is that you may want to convert your data into a series of aligned rasters which you can overlay and treat as a 3 dimensional array.

MappaGnosis
  • 1,179
  • 1
  • 11
  • 25
  • Yes, I'm looking for a convert solution, to bring data to the most convenient form. It's actually could be a 2 dimensional array, with latitude and longitude as its dimensions (ofcourse with specified accuracy). I've already found maps and layers in of the area I need in shape format, and the only thing left on this stage is to learn how to deal with this data. I can convert vector data to raster, but I assume that it will better to know how to deal with vector data directly. Hope my explanation looks more clear now. – kmityak Dec 21 '11 at 17:14