simplexspatial / osm4scala

Scala and Spark library focused on reading OpenStreetMap Pbf files.
https://simplexspatial.github.io/osm4scala/
MIT License
79 stars 17 forks source link

enable reading of pbfs with node location for ways #110

Open sergiupantiru opened 1 year ago

sergiupantiru commented 1 year ago

Hello,

I've looked into adding lat/long support for Ways. I know that osmium can add location on ways and that some other tools can read it. This would allow you to create the WKT of the way without too much headache.

I've added the lat/lon, the same as the osmformat.proto

message Way {
   required int64 id = 1;
   // Parallel arrays.
   repeated uint32 keys = 2 [packed = true];
   repeated uint32 vals = 3 [packed = true];

   optional Info info = 4;

   repeated sint64 refs = 8 [packed = true];  // DELTA coded

+  repeated sint64 lat = 9 [packed = true]; // DELTA coded, optional
+  repeated sint64 lon = 10 [packed = true]; // DELTA coded, optional
}

In the OsmSqlEtity I've added a new schema for way.nodes

  lazy val wayNodeSchema = StructType(
    Seq(
      StructField(FIELD_ID, LongType, true),
      StructField(FIELD_LATITUDE, DoubleType, true),
      StructField(FIELD_LONGITUDE, DoubleType, true)
    ))

Before I make a PR I wanted to know your opinion if this would be acceptable.

Thanks in advance

angelcervera commented 1 year ago

Do you know if they are used in any of the official pbf files? If that is the case, it is fine to add it, but I'm pretty sure that it will be necessary to add more code to read and manage it properly (ex. They are deltas, so it's necessary to calculate the real value).

FYI: @angelcerveraroldan

sergiupantiru commented 1 year ago

I don't think there are official pbfs that already have geometry, but with osmium you can add it. The lat/lon is present in the pbf format https://wiki.openstreetmap.org/wiki/PBF_Format.

I do have more code on a branch, and will ask for a PR.

angelcervera commented 1 year ago

Feel free to create the PR. Could you find a small pbf with this data as example and add it into the testing?

sergiupantiru commented 1 year ago

I've added Monaco with geometry and added some test cases

angelcervera commented 1 year ago

Forget what I said about Feroe Islands. Monaco is the one used for testing, so good. BTW, be careful to don't add data about users in the repo. monaco-anonymized.osm.pbf is monaco without history to avoid to add personal info.

sergiupantiru commented 1 year ago

Forget what I said about Feroe Islands. Monaco is the one used for testing, so good.

BTW, be careful to don't add data about users in the repo. monaco-anonymized.osm.pbf is monaco without history to avoid to add personal info.

I just added way node location on the Monaco file from the repo. Should be exactly the same + lay/long

angelcervera commented 1 year ago

@sergiupantiru Thanks for the PR. Give me few days to find free time to do the code review.