osm-simplify 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- osm_simplify-1.0.0/PKG-INFO +12 -0
- osm_simplify-1.0.0/main.py +141 -0
- osm_simplify-1.0.0/osm_simplify.egg-info/PKG-INFO +12 -0
- osm_simplify-1.0.0/osm_simplify.egg-info/SOURCES.txt +7 -0
- osm_simplify-1.0.0/osm_simplify.egg-info/dependency_links.txt +1 -0
- osm_simplify-1.0.0/osm_simplify.egg-info/requires.txt +1 -0
- osm_simplify-1.0.0/osm_simplify.egg-info/top_level.txt +1 -0
- osm_simplify-1.0.0/pyproject.toml +22 -0
- osm_simplify-1.0.0/setup.cfg +4 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: osm-simplify
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A lightweight, dependency-minimal Python library for querying OpenStreetMap data.
|
|
5
|
+
Author: Dogu H.
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: requests>=2.0.0
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
API_DICTIONARY = """
|
|
2
|
+
.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
|
|
3
|
+
OSM-SIMPLIFY QUICK API DICTIONARY
|
|
4
|
+
.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
|
|
5
|
+
|
|
6
|
+
CORE CLASSES & EXCEPTIONS
|
|
7
|
+
|
|
8
|
+
. GeoFinder(lat, lon, ...) : Main search engine (remote or local offline).
|
|
9
|
+
. Place : Simple data container for a found spot.
|
|
10
|
+
. Category : Pre-built, ready to use, simplified OSM tag presets.
|
|
11
|
+
. OverpassServerError : Raised when all remote public mirrors are busy or down.
|
|
12
|
+
|
|
13
|
+
CREATING A SEARCH INSTANCE :|
|
|
14
|
+
|
|
15
|
+
. GeoFinder(lat, lon, location_name="...", local_file=None)
|
|
16
|
+
- Direct coordinate initialization.
|
|
17
|
+
- Pass `local_file="sample.osm"` for %100 offline local XML parsing.
|
|
18
|
+
|
|
19
|
+
. GeoFinder.from_address(addr, city, country=None, local_file=None)
|
|
20
|
+
- Resolves text to coordinates via Nominatim with Photon fuzzy fallback.
|
|
21
|
+
|
|
22
|
+
SEARCH METHODS :/
|
|
23
|
+
|
|
24
|
+
. location.get_nearby(category, radius_m=1000, raise_on_error=False)
|
|
25
|
+
- Returns a list of 'Place' objects, strictly sorted by distance_m.
|
|
26
|
+
- Automatically clamps radius_m to MAX_RADIUS_M (1000m max) if the user tries to look for bigger radius'.
|
|
27
|
+
- Expands automatically the necessary key-value selectors across node, way, and relation primitives.
|
|
28
|
+
- Builtin memory cache to make repeated/similiar searches instantly (_query_cache).
|
|
29
|
+
- Set 'raise_on_error=True' to explicitly catch server congestion.
|
|
30
|
+
|
|
31
|
+
. location.get_closest(category, radius_m=1000)
|
|
32
|
+
- Returns strictly the single closest 'Place' object, or 'None' if no match.
|
|
33
|
+
|
|
34
|
+
PLACE OBJECT ATTRIBUTES ;)
|
|
35
|
+
|
|
36
|
+
. place.name (str) : Main location name (or its brand/type).
|
|
37
|
+
. place.category (str) : Parent group ("food", "park", "monument").
|
|
38
|
+
. place.subtype (str) : Specific OSM tag ("restaurant", "artwork", "memorial").
|
|
39
|
+
. place.lat, .lon (float) : Extracted coordinates (or area center lat/lon).
|
|
40
|
+
. place.distance_m (int) : Real world Haversine distance in meters from origin with approx calculation.
|
|
41
|
+
. place.to_dict() (dict) : Serializes Place instance to standard dictionary.
|
|
42
|
+
|
|
43
|
+
BUILT-IN PRESETS :)
|
|
44
|
+
|
|
45
|
+
. Category.MONUMENT : Monuments, statues, memorials, public artwork, obelisks.
|
|
46
|
+
. Category.PARK : Parks, gardens, playgrounds, dog parks, green spaces.
|
|
47
|
+
. Category.FOOD : Restaurants, cafes, bars, pubs, fast food, food court, ice cream.
|
|
48
|
+
|
|
49
|
+
CUSTOM PRESETS & AUTOMATIC TAG EXPANSION
|
|
50
|
+
|
|
51
|
+
. Define a custom dict without worrying about explicit node/way/nwr syntax:
|
|
52
|
+
MY_PRESET = {
|
|
53
|
+
"name": "fountain",
|
|
54
|
+
"overpass": ('["amenity"="fountain"]',)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
. The engine automatically expands raw selectors into explicit node, way,
|
|
58
|
+
and relation queries behind the scenes, therefore its easy to use.
|
|
59
|
+
|
|
60
|
+
OFFLINE LOCAL FILE MODE (.osm XML)
|
|
61
|
+
|
|
62
|
+
. Pass a local file path to bypass all HTTP endpoints have a problem free, fast library usage:
|
|
63
|
+
geo = GeoFinder(45.0705, 7.6869, local_file="turin_sample.osm")
|
|
64
|
+
places = geo.get_nearby(Category.FOOD, radius_m=500)
|
|
65
|
+
|
|
66
|
+
.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
# EXAMPLE USAGE :)
|
|
70
|
+
|
|
71
|
+
import os
|
|
72
|
+
from geo_finder import GeoFinder, Category, OverpassServerError
|
|
73
|
+
|
|
74
|
+
LOCAL_OSM = "sample_lib.osm"
|
|
75
|
+
|
|
76
|
+
def main():
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
# creating a referance point via address string (uses Nominatim/Photon under the hood)
|
|
81
|
+
try:
|
|
82
|
+
spot = GeoFinder.from_address("Piazza Castello", "Turin", "Italy")
|
|
83
|
+
#spot = GeoFinder.from_address("Piazza Castello", "Turin", "Italy") also possible to negate the country name
|
|
84
|
+
except ValueError:
|
|
85
|
+
# direct lat/lon initialization fallback just in case
|
|
86
|
+
spot = GeoFinder(45.0705, 7.6869, "Piazza Castello")
|
|
87
|
+
|
|
88
|
+
# if public Overpass mirrors are busy or offline, attach a local .osm XML file
|
|
89
|
+
if os.path.exists(LOCAL_OSM):
|
|
90
|
+
spot.local_file = LOCAL_OSM
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
# nearby search
|
|
95
|
+
# can search up to 1000m (MAX_RADIUS_M) with auto sorted results available
|
|
96
|
+
|
|
97
|
+
restaurants = spot.get_nearby(Category.FOOD, radius_m=500)
|
|
98
|
+
|
|
99
|
+
print(f"Found {len(restaurants)} food spots within 500m of {spot.location_name}:")
|
|
100
|
+
for place in restaurants[:3]:
|
|
101
|
+
# Place is a dataclass with .name, .category, .subtype, .lat, .lon, .distance_m
|
|
102
|
+
print(f" *** {place.name} ({place.subtype}): {place.distance_m}m away")
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
# closest match searching
|
|
106
|
+
|
|
107
|
+
closest_monument = spot.get_closest(Category.MONUMENT, radius_m=1000)
|
|
108
|
+
if closest_monument:
|
|
109
|
+
print(f"\nClosest monument: {closest_monument.name} at {closest_monument.distance_m}m")
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
# creating custom preset/tag category
|
|
113
|
+
|
|
114
|
+
# you can also get away with NOT writing a fix plate like nwr (node, way, relation)
|
|
115
|
+
# those plate blocks are contructed by geo_finder.py
|
|
116
|
+
|
|
117
|
+
FOUNTAIN_PRESET = {
|
|
118
|
+
"name": "fountain",
|
|
119
|
+
"overpass": ('["amenity"="fountain"]',)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
fountains = spot.get_nearby(FOUNTAIN_PRESET, radius_m=800)
|
|
123
|
+
print(f"\nFountains found: {len(fountains)}")
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
# dict convert and offline-only mode
|
|
127
|
+
|
|
128
|
+
if restaurants:
|
|
129
|
+
# converting our place object to a python dict
|
|
130
|
+
sample_dict = restaurants[0].to_dict()
|
|
131
|
+
print("\nSerialized Place dict:", sample_dict)
|
|
132
|
+
|
|
133
|
+
# pure offline initialization (bypasses network entirely)
|
|
134
|
+
if os.path.exists(LOCAL_OSM):
|
|
135
|
+
offline_spot = GeoFinder(45.0705, 7.6869, location_name="Offline Map", local_file=LOCAL_OSM)
|
|
136
|
+
parks = offline_spot.get_nearby(Category.PARK, radius_m=1000)
|
|
137
|
+
print(f"\n[Offline Engine] Parks found in {LOCAL_OSM}: {len(parks)}")
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
if __name__ == "__main__":
|
|
141
|
+
main()
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: osm-simplify
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A lightweight, dependency-minimal Python library for querying OpenStreetMap data.
|
|
5
|
+
Author: Dogu H.
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: requests>=2.0.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests>=2.0.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
main
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "osm-simplify"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "A lightweight, dependency-minimal Python library for querying OpenStreetMap data."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Dogu H." }
|
|
14
|
+
]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
]
|
|
20
|
+
dependencies = [
|
|
21
|
+
"requests>=2.0.0"
|
|
22
|
+
]
|