Skip to content

faq 22020099

Billy Charlton edited this page Sep 5, 2018 · 2 revisions

How to convert shapefile to MATSim network?

by Davi Guggisberg on 2014-11-24 20:54:23


I couldn't find and answer in the documentation. I've been working with OSM files so far but soon I will receive .shp as input files and don't know how to work with them. Can you advice me on that? Thank you!


Comments: 3


Re: How to convert shapefile to MATSim network?

by Johan W. Joubert on 2014-11-25 05:23:38

Davi,

there is a class 

org.matsim.core.utils.gis.ShapeFileReader

that might help you. Specifically, have a look at the Javadoc from line 68 on how to use the class if you want access to the metadata (which I assume you will need if you to read in number of lanes, length, directionality, etc) 

 

ShapeFileReader sfr = new ShapeFileReader();
 Collection<SimpleFeature> features = sfr.readFileAndInitialize(shapefile);
 for(SimpleFeature feature: features){
 	Geometry geo = (Geometry) feature.getDefaultGeometry();
     List<Object> attributes = feature.getAttributes();
     for(Object o : attributes){
 		/* You can check the data type of an attribute, 
 		   and cast accordingly, or just fetch certain
 		   attributes. */
 	}

 	/* One example to check if it is points. */
     if(geo instanceof Point){
         /* It is a point. */
     } else{
         throw new RuntimeException("The shapefile does not contain Point(s)!");
     }
 }


 

 


Re: How to convert shapefile to MATSim network?

by Marcel Rieser on 2014-11-25 08:36:00

An alternative solution using python libraries is outlined in this gis.stackexchange post: http://gis.stackexchange.com/questions/113516/shapefile-to-network-xml


Re: How to convert shapefile to MATSim network?

by Davi Guggisberg on 2014-12-01 13:19:42

I haven't tried them so far but thank you for the answers! I will receive the files in the following weeks and will try these methods.

Clone this wiki locally