matsim-org / matsim-code-examples

A repository containing code examples around MATSim
GNU General Public License v3.0
77 stars 175 forks source link

Network OSM #315

Open khzannat26 opened 4 years ago

khzannat26 commented 4 years ago

I am downloading network from OSM that I would like to use in MATSim for my PhD research. However, I've managed to download road width, lane number and maximum speed from OSM. How can I estimate the capacity? Is there any code to prepare network for MATSim using OSM?

mrieser commented 4 years ago

Have a look at chapter 18 of the MATSim Book, or of the extracted user guide at http://ci.matsim.org:8080/job/MATSim-Book/ws/partOne-latest.pdf .

Janekdererste commented 4 years ago

After you've read the user guide, you may have a look here:

https://github.com/matsim-org/matsim-libs/tree/master/contribs/osm/src/main/java/org/matsim/contrib/osm/examples

This is our current facility to convert Osm-Networks into Matsim-Networks.

khzannat26 commented 4 years ago

Hi Thank you for your suggestion. As I need only driving way and my study area is in Dhaka, Bangladesh. I am getting many errors. My code and error text is Attached below. package org.matsim.codeexamples; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Network; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.network.algorithms.NetworkCleaner; import org.matsim.core.network.io.NetworkWriter; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.core.utils.geometry.CoordinateTransformation; import org.matsim.core.utils.geometry.transformations.TransformationFactory; import org.matsim.core.utils.io.OsmNetworkReader; public class RunPNetworkGenerator {

public static void main(String[] args) {
    String osm = "D:/PhD/merged-network.osm";
    CoordinateTransformation ct =    TransformationFactory.getCoordinateTransformation(TransformationFactory.WGS84, "EPSG:3106");
    Config config = ConfigUtils.createConfig();
    Scenario scenario = ScenarioUtils.createScenario(config);
    Network network = scenario.getNetwork();

    OsmNetworkReader onr = new OsmNetworkReader(network,ct);
    onr.parse(osm);
    new NetworkCleaner().run(network);
    new NetworkWriter(network).write("D:/PhD/final-network.xml.gz");

}

}

2020-04-06 12:15:05,500 WARN MGC:175 Assuming that coordinates are in longitude first notation, i.e. (longitude, latitude). 2020-04-06 12:15:06,013 INFO Logger:? dataFileCache open start 2020-04-06 12:15:06,254 WARN MGC:175 Assuming that coordinates are in longitude first notation, i.e. (longitude, latitude). Apr 06, 2020 12:15:06 PM org.geotools.factory.FactoryRegistry scanForPlugins WARNING: Can't load a service for category "MathTransformProvider". Cause is "ServiceConfigurationError: org.geotools.referencing.operation.MathTransformProvider: Provider org.geotools.referencing.operation.projection.LambertConformalEsriProvider could not be instantiated". java.util.ServiceConfigurationError: org.geotools.referencing.operation.MathTransformProvider: Provider org.geotools.referencing.operation.projection.LambertConformalEsriProvider could not be instantiated at java.util.ServiceLoader.fail(Unknown Source) at java.util.ServiceLoader.access$100(Unknown Source) at java.util.ServiceLoader$LazyIterator.nextService(Unknown Source) at java.util.ServiceLoader$LazyIterator.next(Unknown Source) at java.util.ServiceLoader$1.next(Unknown Source) at org.geotools.factory.FactoryRegistry.register(FactoryRegistry.java:826) at org.geotools.factory.FactoryRegistry.scanForPlugins(FactoryRegistry.java:772) at org.geotools.factory.FactoryRegistry.scanForPluginsIfNeeded(FactoryRegistry.java:805) at org.geotools.factory.FactoryRegistry.getServiceProviders(FactoryRegistry.java:196) at org.geotools.referencing.operation.DefaultMathTransformFactory.getProvider(DefaultMathTransformFactory.java:282) at org.geotools.referencing.operation.DefaultMathTransformFactory.getDefaultParameters(DefaultMathTransformFactory.java:316) at org.geotools.referencing.factory.epsg.DirectEpsgFactory.createOperationMethod(DirectEpsgFactory.java:2340) at org.geotools.referencing.factory.BufferedAuthorityFactory.createOperationMethod(BufferedAuthorityFactory.java:1018) at org.geotools.referencing.factory.epsg.DirectEpsgFactory.createCoordinateOperation(DirectEpsgFactory.java:2648) at org.geotools.referencing.factory.BufferedAuthorityFactory.createCoordinateOperation(BufferedAuthorityFactory.java:1041) at org.geotools.referencing.factory.epsg.DirectEpsgFactory.createCoordinateReferenceSystem(DirectEpsgFactory.java:2008) at org.geotools.referencing.factory.BufferedAuthorityFactory.createCoordinateReferenceSystem(BufferedAuthorityFactory.java:783) at org.geotools.referencing.factory.AuthorityFactoryAdapter.createCoordinateReferenceSystem(AuthorityFactoryAdapter.java:801) at org.geotools.referencing.factory.BufferedAuthorityFactory.createCoordinateReferenceSystem(BufferedAuthorityFactory.java:783) at org.geotools.referencing.factory.AuthorityFactoryAdapter.createCoordinateReferenceSystem(AuthorityFactoryAdapter.java:801) at org.geotools.referencing.factory.FallbackAuthorityFactory.createCoordinateReferenceSystem(FallbackAuthorityFactory.java:640) at org.geotools.referencing.factory.AuthorityFactoryAdapter.createCoordinateReferenceSystem(AuthorityFactoryAdapter.java:801) at org.geotools.referencing.factory.ThreadedAuthorityFactory.createCoordinateReferenceSystem(ThreadedAuthorityFactory.java:731) at org.geotools.referencing.DefaultAuthorityFactory.createCoordinateReferenceSystem(DefaultAuthorityFactory.java:179) at org.geotools.referencing.CRS.decode(CRS.java:520) at org.matsim.core.utils.geometry.geotools.MGC.getCRS(MGC.java:176) at org.matsim.core.utils.geometry.transformations.GeotoolsTransformation.(GeotoolsTransformation.java:58) at org.matsim.core.utils.geometry.transformations.TransformationFactory.getCoordinateTransformation(TransformationFactory.java:80) at org.matsim.codeexamples.RunPNetworkGenerator.main(RunPNetworkGenerator.java:19) Caused by: java.lang.NoSuchMethodError: org.geotools.referencing.operation.projection.LambertConformalEsriProvider.createOptionalDescriptor([Lorg/opengis/referencing/ReferenceIdentifier;DDLjavax/measure/Unit;)Lorg/opengis/parameter/ParameterDescriptor; at org.geotools.referencing.operation.projection.LambertConformalEsriProvider.(LambertConformalEsriProvider.java:43) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at java.lang.Class.newInstance(Unknown Source) ... 27 more

Apr 06, 2020 12:15:06 PM org.geotools.factory.FactoryRegistry scanForPlugins WARNING: Can't load a service for category "MathTransformProvider". Cause is "ServiceConfigurationError: org.geotools.referencing.operation.MathTransformProvider: Provider org.geotools.referencing.operation.projection.GeostationarySatellite$Provider could not be instantiated". java.util.ServiceConfigurationError: org.geotools.referencing.operation.MathTransformProvider: Provider org.geotools.referencing.operation.projection.GeostationarySatellite$Provider could not be instantiated at java.util.ServiceLoader.fail(Unknown Source) at java.util.ServiceLoader.access$100(Unknown Source) at java.util.ServiceLoader$LazyIterator.nextService(Unknown Source) at java.util.ServiceLoader$LazyIterator.next(Unknown Source) at java.util.ServiceLoader$1.next(Unknown Source) at org.geotools.factory.FactoryRegistry.register(FactoryRegistry.java:826) at org.geotools.factory.FactoryRegistry.scanForPlugins(FactoryRegistry.java:772) at org.geotools.factory.FactoryRegistry.scanForPluginsIfNeeded(FactoryRegistry.java:805) at org.geotools.factory.FactoryRegistry.getServiceProviders(FactoryRegistry.java:196) at org.geotools.referencing.operation.DefaultMathTransformFactory.getProvider(DefaultMathTransformFactory.java:282) at org.geotools.referencing.operation.DefaultMathTransformFactory.getDefaultParameters(DefaultMathTransformFactory.java:316) at org.geotools.referencing.factory.epsg.DirectEpsgFactory.createOperationMethod(DirectEpsgFactory.java:2340) at org.geotools.referencing.factory.BufferedAuthorityFactory.createOperationMethod(BufferedAuthorityFactory.java:1018) at org.geotools.referencing.factory.epsg.DirectEpsgFactory.createCoordinateOperation(DirectEpsgFactory.java:2648) at org.geotools.referencing.factory.BufferedAuthorityFactory.createCoordinateOperation(BufferedAuthorityFactory.java:1041) at org.geotools.referencing.factory.epsg.DirectEpsgFactory.createCoordinateReferenceSystem(DirectEpsgFactory.java:2008) at org.geotools.referencing.factory.BufferedAuthorityFactory.createCoordinateReferenceSystem(BufferedAuthorityFactory.java:783) at org.geotools.referencing.factory.AuthorityFactoryAdapter.createCoordinateReferenceSystem(AuthorityFactoryAdapter.java:801) at org.geotools.referencing.factory.BufferedAuthorityFactory.createCoordinateReferenceSystem(BufferedAuthorityFactory.java:783) at org.geotools.referencing.factory.AuthorityFactoryAdapter.createCoordinateReferenceSystem(AuthorityFactoryAdapter.java:801) at org.geotools.referencing.factory.FallbackAuthorityFactory.createCoordinateReferenceSystem(FallbackAuthorityFactory.java:640) at org.geotools.referencing.factory.AuthorityFactoryAdapter.createCoordinateReferenceSystem(AuthorityFactoryAdapter.java:801) at org.geotools.referencing.factory.ThreadedAuthorityFactory.createCoordinateReferenceSystem(ThreadedAuthorityFactory.java:731) at org.geotools.referencing.DefaultAuthorityFactory.createCoordinateReferenceSystem(DefaultAuthorityFactory.java:179) at org.geotools.referencing.CRS.decode(CRS.java:520) at org.matsim.core.utils.geometry.geotools.MGC.getCRS(MGC.java:176) at org.matsim.core.utils.geometry.transformations.GeotoolsTransformation.(GeotoolsTransformation.java:58) at org.matsim.core.utils.geometry.transformations.TransformationFactory.getCoordinateTransformation(TransformationFactory.java:80) at org.matsim.codeexamples.RunPNetworkGenerator.main(RunPNetworkGenerator.java:19) Caused by: java.lang.NoSuchMethodError: org.geotools.referencing.operation.projection.GeostationarySatellite$Provider.createDescriptor([Lorg/opengis/referencing/ReferenceIdentifier;DDDLjavax/measure/Unit;)Lorg/opengis/parameter/ParameterDescriptor; at org.geotools.referencing.operation.projection.GeostationarySatellite$Provider.(GeostationarySatellite.java:322) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at java.lang.Class.newInstance(Unknown Source) ... 27 more

Apr 06, 2020 12:15:06 PM org.geotools.factory.FactoryRegistry scanForPlugins WARNING: Can't load a service for category "MathTransformProvider". Cause is "ServiceConfigurationError: org.geotools.referencing.operation.MathTransformProvider: Provider org.geotools.referencing.operation.projection.AzimuthalEquidistant$Provider could not be instantiated". java.util.ServiceConfigurationError: org.geotools.referencing.operation.MathTransformProvider: Provider org.geotools.referencing.operation.projection.AzimuthalEquidistant$Provider could not be instantiated at java.util.ServiceLoader.fail(Unknown Source) at java.util.ServiceLoader.access$100(Unknown Source) at java.util.ServiceLoader$LazyIterator.nextService(Unknown Source) at java.util.ServiceLoader$LazyIterator.next(Unknown Source) at java.util.ServiceLoader$1.next(Unknown Source) at org.geotools.factory.FactoryRegistry.register(FactoryRegistry.java:826) at org.geotools.factory.FactoryRegistry.scanForPlugins(FactoryRegistry.java:772) at org.geotools.factory.FactoryRegistry.scanForPluginsIfNeeded(FactoryRegistry.java:805) at org.geotools.factory.FactoryRegistry.getServiceProviders(FactoryRegistry.java:196) at org.geotools.referencing.operation.DefaultMathTransformFactory.getProvider(DefaultMathTransformFactory.java:282) at org.geotools.referencing.operation.DefaultMathTransformFactory.getDefaultParameters(DefaultMathTransformFactory.java:316) at org.geotools.referencing.factory.epsg.DirectEpsgFactory.createOperationMethod(DirectEpsgFactory.java:2340) at org.geotools.referencing.factory.BufferedAuthorityFactory.createOperationMethod(BufferedAuthorityFactory.java:1018) at org.geotools.referencing.factory.epsg.DirectEpsgFactory.createCoordinateOperation(DirectEpsgFactory.java:2648) at org.geotools.referencing.factory.BufferedAuthorityFactory.createCoordinateOperation(BufferedAuthorityFactory.java:1041) at org.geotools.referencing.factory.epsg.DirectEpsgFactory.createCoordinateReferenceSystem(DirectEpsgFactory.java:2008) at org.geotools.referencing.factory.BufferedAuthorityFactory.createCoordinateReferenceSystem(BufferedAuthorityFactory.java:783) at org.geotools.referencing.factory.AuthorityFactoryAdapter.createCoordinateReferenceSystem(AuthorityFactoryAdapter.java:801) at org.geotools.referencing.factory.BufferedAuthorityFactory.createCoordinateReferenceSystem(BufferedAuthorityFactory.java:783) at org.geotools.referencing.factory.AuthorityFactoryAdapter.createCoordinateReferenceSystem(AuthorityFactoryAdapter.java:801) at org.geotools.referencing.factory.FallbackAuthorityFactory.createCoordinateReferenceSystem(FallbackAuthorityFactory.java:640) at org.geotools.referencing.factory.AuthorityFactoryAdapter.createCoordinateReferenceSystem(AuthorityFactoryAdapter.java:801) at org.geotools.referencing.factory.ThreadedAuthorityFactory.createCoordinateReferenceSystem(ThreadedAuthorityFactory.java:731) at org.geotools.referencing.DefaultAuthorityFactory.createCoordinateReferenceSystem(DefaultAuthorityFactory.java:179) at org.geotools.referencing.CRS.decode(CRS.java:520) at org.matsim.core.utils.geometry.geotools.MGC.getCRS(MGC.java:176) at org.matsim.core.utils.geometry.transformations.GeotoolsTransformation.(GeotoolsTransformation.java:58) at org.matsim.core.utils.geometry.transformations.TransformationFactory.getCoordinateTransformation(TransformationFactory.java:80) at org.matsim.codeexamples.RunPNetworkGenerator.main(RunPNetworkGenerator.java:19) Caused by: java.lang.NoSuchFieldError: LONGITUDE_OF_CENTRE at org.geotools.referencing.operation.projection.AzimuthalEquidistant$Provider.(AzimuthalEquidistant.java:429) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at java.lang.Class.newInstance(Unknown Source) ... 27 more

2020-04-06 12:15:07,525 INFO Config:561 setting context to [file:/D:/MATsim/matsim-input/] 2020-04-06 12:15:07,707 INFO Config:561 setting context to [file:/D:/MATsim/matsim-input/] 2020-04-06 12:15:07,785 INFO OsmNetworkReader:137 Falling back to default values. 2020-04-06 12:15:07,785 WARN OsmNetworkReader:199 No hierarchy layer specified. Will convert every highway specified by setHighwayDefaults. 2020-04-06 12:15:07,791 INFO MatsimXmlParser:147 starting to parse xml from file D:/PhD Research/Item 2_Agenbasedmodel/Data/Network_data_preparation/merged-network.osm ... 2020-04-06 12:15:08,009 INFO Counter:61 node 1 2020-04-06 12:15:08,009 INFO Counter:61 node 2 2020-04-06 12:15:08,009 INFO Counter:61 node 4 2020-04-06 12:15:08,025 INFO Counter:61 node 8 2020-04-06 12:15:08,025 INFO Counter:61 node 16 2020-04-06 12:15:08,025 INFO Counter:61 node 32 2020-04-06 12:15:08,025 INFO Counter:61 node 64 2020-04-06 12:15:08,025 INFO Counter:61 node 128 2020-04-06 12:15:08,041 INFO Counter:61 node 256 2020-04-06 12:15:08,056 INFO Counter:61 node 512 2020-04-06 12:15:08,103 INFO Counter:61 node 1024 2020-04-06 12:15:08,134 INFO Counter:61 node 2048 2020-04-06 12:15:08,181 INFO Counter:61 node 4096 2020-04-06 12:15:08,259 INFO Counter:61 node 8192 2020-04-06 12:15:08,400 INFO Counter:61 node 16384 2020-04-06 12:15:08,681 INFO Counter:61 node 32768 2020-04-06 12:15:08,877 INFO Counter:61 node 65536 2020-04-06 12:15:09,158 INFO Counter:61 node 131072 2020-04-06 12:15:09,799 INFO Counter:61 node 262144 2020-04-06 12:15:11,787 INFO Counter:61 node 524288 2020-04-06 12:15:31,376 INFO Counter:61 node 1048576 2020-04-06 12:15:37,878 INFO Counter:61 node 2097152 2020-04-06 12:15:49,932 INFO Counter:61 node 4194304 Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded at org.geotools.referencing.operation.transform.ConcatenatedTransform.transform(ConcatenatedTransform.java:458) at org.geotools.referencing.operation.transform.ConcatenatedTransform.transform(ConcatenatedTransform.java:465) at org.geotools.referencing.operation.transform.ConcatenatedTransformDirect.transform(ConcatenatedTransformDirect.java:80) at org.geotools.geometry.jts.DefaultCoordinateSequenceTransformer.transform(DefaultCoordinateSequenceTransformer.java:123) at org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.projectCoordinateSequence(GeometryCoordinateSequenceTransformer.java:295) at org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.transformPoint(GeometryCoordinateSequenceTransformer.java:282) at org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.transform(GeometryCoordinateSequenceTransformer.java:148) at org.geotools.geometry.jts.JTS.transform(JTS.java:439) at org.matsim.core.utils.geometry.transformations.GeotoolsTransformation.transform(GeotoolsTransformation.java:71) at org.matsim.core.utils.io.OsmNetworkReader$OsmXmlParser.startTag(OsmNetworkReader.java:845) at org.matsim.core.utils.io.MatsimXmlParser.startElement(MatsimXmlParser.java:341) at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source) at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source) at org.matsim.core.utils.io.MatsimXmlParser.parse(MatsimXmlParser.java:191) at org.matsim.core.utils.io.MatsimXmlParser.readFile(MatsimXmlParser.java:149) at org.matsim.core.utils.io.OsmNetworkReader.parse(OsmNetworkReader.java:225) at org.matsim.core.utils.io.OsmNetworkReader.parse(OsmNetworkReader.java:177) at org.matsim.codeexamples.RunPNetworkGenerator.main(RunPNetworkGenerator.java:25)

Janekdererste commented 4 years ago

The coordinate Transformations are downloaded from the internet. Make sure you are online, the application may access the internet and (if that applies to your case) your proxy configurations of your operating system and your java Virtual Machine are set up correctly.

jfbischoff commented 4 years ago

If you have problems setting up your internet connection, you may also enter the Coordinate Transformations as Well-Known-Text.

Janekdererste commented 4 years ago

@jfbischoff how would you specify a transformation in wkt? I only know that format for describing geometries. (Asking for curiosity)

jfbischoff commented 4 years ago

Sure, take for example, EPSG:2056: https://epsg.io/2056 then the WKT is .... PROJCS["CH1903+ / LV95",GEOGCS["CH1903+",DATUM["CH1903+",SPHEROID["Bessel 1841",6377397.155,299.1528128,AUTHORITY["EPSG","7004"]],TOWGS84[674.374,15.056,405.346,0,0,0,0],AUTHORITY["EPSG","6150"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4150"]],PROJECTION["Hotine_Oblique_Mercator_Azimuth_Center"],PARAMETER["latitude_of_center",46.95240555555556],PARAMETER["longitude_of_center",7.439583333333333],PARAMETER["azimuth",90],PARAMETER["rectified_grid_angle",90],PARAMETER["scale_factor",1],PARAMETER["false_easting",2600000],PARAMETER["false_northing",1200000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Y",EAST],AXIS["X",NORTH],AUTHORITY["EPSG","2056"]]

Looks ugly but works well if there is a very nasty firewall in your setup or you run your linux cluster using floppy disks :-)

Janekdererste commented 4 years ago

Looks ugly but works well if there is a very nasty firewall in your setup or you run your linux cluster using floppy disks :-)

Better save than sorry!