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?

  • $\begingroup$ 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. $\endgroup$ – bobthechemist Sep 16 '13 at 13:04

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];


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/@...

  • $\begingroup$ Thanks. Does the job perfectly! $\endgroup$ – my account_ram Sep 16 '13 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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