Skip to content

Commit c4c0027

Browse files
committed
Update script to support parameters
1 parent 4cb3189 commit c4c0027

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed
Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,38 @@
1-
"""
2-
python /scripts/extents.py
3-
"""
4-
5-
import mapscript
6-
7-
mapfile = "/etc/mapserver/lakes.map"
8-
m = mapscript.mapObj(mapfile)
9-
10-
lyr = m.getLayerByName("lakes")
11-
extent = lyr.getExtent()
12-
13-
original_projection_code = m.getProjection()
14-
original_projection = mapscript.projectionObj(original_projection_code)
15-
16-
webmercator = mapscript.projectionObj("epsg:3857")
17-
18-
extent_string = f"[{extent.minx}, {extent.miny}, {extent.maxx}, {extent.maxy}]"
19-
print(extent_string)
20-
21-
# reprojection is done in-place
22-
extent.project(original_projection, webmercator)
23-
24-
extent_string = f"[{extent.minx}, {extent.miny}, {extent.maxx}, {extent.maxy}]"
25-
print(extent_string)
26-
27-
center = f"[{(extent.maxx + extent.minx) / 2}, {(extent.maxy + extent.miny) / 2}]"
28-
print(center)
29-
30-
print("Done!")
1+
"""
2+
python /scripts/extents.py --mapfile "/etc/mapserver/arcgis.map"
3+
"""
4+
5+
import mapscript
6+
import argparse
7+
8+
9+
def get_extent_and_center(mapfile):
10+
m = mapscript.mapObj(mapfile)
11+
extent = m.extent
12+
13+
original_projection_code = m.getProjection()
14+
original_projection = mapscript.projectionObj(original_projection_code)
15+
16+
webmercator = mapscript.projectionObj("epsg:3857")
17+
18+
extent_string = f"[{extent.minx}, {extent.miny}, {extent.maxx}, {extent.maxy}]"
19+
print(f"Original extent {original_projection_code}: {extent_string}")
20+
21+
# reprojection is done in-place
22+
extent.project(original_projection, webmercator)
23+
24+
extent_string = f"[{extent.minx}, {extent.miny}, {extent.maxx}, {extent.maxy}]"
25+
print(f"New extent epsg:3857: {extent_string}")
26+
27+
center = f"[{(extent.maxx + extent.minx) / 2}, {(extent.maxy + extent.miny) / 2}]"
28+
print(f"Center: {center}")
29+
30+
31+
if __name__ == "__main__":
32+
parser = argparse.ArgumentParser(
33+
description="Print map extent and center in WebMercator"
34+
)
35+
parser.add_argument("--mapfile", type=str, help="Path to the MapServer mapfile")
36+
args = parser.parse_args()
37+
get_extent_and_center(args.mapfile)
38+
print("Done!")

0 commit comments

Comments
 (0)