Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I saw this example wherein the CityData gives the map of a city.

But this is available for a relatively small set of curated regions.

Is it possible to extract such map, say the topologically connected roadmap (with edges representing edgelengths) of an arbitrary city?

share|improve this question
    
Mma can read GIS shapefiles via Import. If you have access to these files (and many larger cities have GIS departments that make this information publicly available) then you should be able to use it. –  bobthechemist Sep 16 '13 at 13:04
add comment

1 Answer

up vote 9 down vote accepted

I found some free gis data of indian roads. I extracted the india-latest.shp.zip and then imported the roads.shp file. Here is a quick example to extract relevant roads:

(* Make sure to fix the path *)
indiaRoadData = Import["india-latest.shp/roads.shp", "Data"];
(* This just happens to be where the Lines are located in the data, 
    see below for some tips to explore the list  *)
roads = indiaRoadData[[1, 2, 2]];

(* Where's bangalore? *)
bangaloreCenter = {77.56`, 12.97`};

(* Takes a line and returns True if within 1 lat/long unit of bangalore center,
   note that this is a shady test for the sake of this example *)
inBangaloreQ[l_Line] := Sqrt[#.#]<1 &[
       Nearest[l[[1]], bangaloreCenter][[1]] - bangaloreCenter]

(* Extract all roads passing through bangalore *)
bangaloreRoads = Select[roads, inBangaloreQ];

Graphics[bangaloreRoads]

road network

The entire code snippet above took about a minute to run on my computer.

If the road network actually is that dense in rectangular areas or if it's just a sampling bias in the data or the bangalore selection I have no idea.

Beware that this is a ton of data, so don't let the front-end print everything out. When exploring the structure of indiaRoadData don't be shy with Dimensions, //Short and Head/@...

share|improve this answer
    
Thanks. Does the job perfectly! –  my account_ram Sep 16 '13 at 16:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.