-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from shapely.geometry import shape | ||
from osmdiff.osm import Node, Way, Relation | ||
|
||
# Create a node with coordinates | ||
node = Node() | ||
node.attribs = {"lon": "-122.4", "lat": "37.7"} | ||
|
||
# Convert to Shapely Point using geo_interface | ||
point = shape(node.__geo_interface__) | ||
print(f"Node as Point: {point}") # POINT (-122.4 37.7) | ||
|
||
# Create a way with nodes | ||
way = Way() | ||
way.nodes = [ | ||
Node(attribs={"lon": "-122.4", "lat": "37.7"}), | ||
Node(attribs={"lon": "-122.4", "lat": "37.8"}), | ||
Node(attribs={"lon": "-122.5", "lat": "37.8"}), | ||
Node(attribs={"lon": "-122.4", "lat": "37.7"}), # Closing the loop | ||
] | ||
|
||
# Convert to Shapely Polygon using geo_interface | ||
polygon = shape(way.__geo_interface__) | ||
print( | ||
f"Way as Polygon: {polygon}" | ||
) # POLYGON ((-122.4 37.7, -122.4 37.8, -122.5 37.8, -122.4 37.7)) | ||
|
||
# Create a relation with members | ||
relation = Relation() | ||
relation.members = [way, node] | ||
|
||
# Convert to Shapely GeometryCollection using geo_interface | ||
collection = shape(relation.__geo_interface__) | ||
print( | ||
f"Relation as Collection: {collection}" | ||
) # GEOMETRYCOLLECTION (POLYGON ((-122.4 37.7, -122.4 37.8, -122.5 37.8, -122.4 37.7)), POINT (-122.4 37.7)) |