Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 10 down vote accepted

I found some free gis data of indian roads. I extracted the 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/@...

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

Your Answer


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.