Open raggabrashtrout opened 3 years ago
I have the same problem. Have you resolved this problem?
Hi I'd like to try and extract populated places and associated tags from, eventually, planet osm Based on your Samples the code bellow is erroring at the foreach loop
protobuf-net nuget is v 3.0.101 latest
Is this something you can help with
also is my linq query going to extract what I'm expecting I realize there needs to be additional filtering For instance in QGIS you can do this
"place" IN ('city','farm','hamlet','isolated_dwelling','neighbourhood','quarter','suburb','town','village')
C# Code
using OsmSharp.Streams; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace OSM_Places { class Program { static void Main(string[] args) { using (var fileStream = File.OpenRead(@"path\to\luxembourg-latest.osm.pbf")) { // create source stream. var source = new PBFOsmStreamSource(fileStream); // let's use linq to leave only objects last touched by the given mapper. var filtered = from osmGeo in source where osmGeo.Type == OsmSharp.OsmGeoType.Node && osmGeo.Tags != null && osmGeo.Tags.Contains("place","point") select osmGeo; var complete = filtered.ToComplete(); foreach (var item in complete) { Console.WriteLine(item.Tags); // Loop through the tags an do something useful } } } } }
I have the same problem. Have you resolved this?
Hi Unfortunately not I didn't get anywhere with OsmSharp I used ogr2ogr to extract the points to a geojson file then used a C# to process it ogr2ogr.exe -f GeoJSON PathTo\antarctica-latest.geojson PathTo\antarctica-latest.osm points
I didn't have big enough HDD to process planet.osm so split into continents
// deserialize JSON directly from a file using (StreamReader file = File.OpenText(jsonFile)) { JsonSerializer serializer = new JsonSerializer(); Root OSMFeatures = (Root)serializer.Deserialize(file, typeof(Root)); foreach (var item in OSMFeatures.features) { // Do Stuff with item } }
HTH
The latest protobuf version OsmSharp supports is 2.x so upgrading to 3.x is not going to work.
The latest protobuf version OsmSharp supports is 2.x so upgrading to 3.x is not going to work.
I have been running into the same issue as mentioned by the other users in this thread, when calling MoveNext on the osmGeoEnumerator variable, an exception with the following message is thrown:
System.MissingMethodException: 'Method not found: 'ProtoBuf.Meta.RuntimeTypeModel ProtoBuf.Meta.TypeModel.Create()'.'
This exception occurs at the following line of code:
while (osmGeoEnumerator.MoveNext() == true)
For context, this is the body of the method in which the exception occurs at:
private void GenerateImageFromPBFFile(string pbfFilePath)
{
FileStream pbfFileStream = File.OpenRead(pbfFilePath);
PBFOsmStreamSource pbfOsmStreamSource = new PBFOsmStreamSource(
pbfFileStream
);
List<OsmGeo> osmGeos = new List<OsmGeo>();
// ProtoBuf.Meta.RuntimeTypeModel
IEnumerator<OsmGeo> osmGeoEnumerator = pbfOsmStreamSource.GetEnumerator();
while (osmGeoEnumerator.MoveNext() == true)
{
osmGeos.Add(osmGeoEnumerator.Current);
}
IFeatureStreamSource features = osmGeos.ToFeatureSource();
foreach(IFeature feature in features)
{
MessageBox.Show(
"New Geometry found: " + feature.Geometry.AsText()
);
}
}
As per your suggestion as seen in the quoted reply at the top of this message, I had tried to downgrade my version of the protobuf-net Nuget package from version 3.2.26 (the latest version of the package as of now) to version 2.3.7. However, although the MissingMethodException no longer occurs, another exception occurs instead with the following message:
System.IO.FileLoadException: 'Could not load file or assembly 'protobuf-net, Version=3.0.0.0, Culture=neutral, PublicKeyToken=257b51d87d2e4d67' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'
This exception occurs at the following line of code:
IEnumerator<OsmGeo> osmGeoEnumerator = pbfOsmStreamSource.GetEnumerator();
The same issue occurs even when using version 2.4.8 of the protobuf-net package instead.
I then upgraded my version of the protobuf-net package to version 3.0.0. However, even on that version, this exception with the following message is thrown:
System.MissingMethodException: 'Method not found: 'ProtoBuf.Meta.RuntimeTypeModel ProtoBuf.Meta.TypeModel.Create()'.'
Again this exception occurs at the following line of code:
while (osmGeoEnumerator.MoveNext() == true)
I was wondering if there was a way to resolve this issue?
Hi I'd like to try and extract populated places and associated tags from, eventually, planet osm
Based on your Samples the code bellow is erroring at the foreach loop
protobuf-net nuget is v 3.0.101 latest
Is this something you can help with
also is my linq query going to extract what I'm expecting I realize there needs to be additional filtering For instance in QGIS you can do this
"place" IN ('city','farm','hamlet','isolated_dwelling','neighbourhood','quarter','suburb','town','village')
C# Code