Skip to content

Instantly share code, notes, and snippets.

@jmcarp
Last active May 23, 2020 23:09
Show Gist options
  • Save jmcarp/59f3a4446e14f59e5e253b834858e872 to your computer and use it in GitHub Desktop.
Save jmcarp/59f3a4446e14f59e5e253b834858e872 to your computer and use it in GitHub Desktop.
gisweb-screenshots
import json
import fiona
import requests
def get_map(base_url, parcel_id, out_path, bbox_scale_factor=1.25):
parcel_id_clean = parcel_id.replace("-", "")
state = {
"Application": "GISWEBApp",
"MapTab": "GISWEBMap",
"Level": "",
"Search": "PropertySearch",
"SearchCriteria": {"ParcelIDautocomplete": parcel_id},
"Action": "0",
"TargetLayer": "ParcelsStacked",
"TargetIds": [parcel_id_clean],
"ActiveMapId": parcel_id_clean,
"ActiveDataId": parcel_id_clean,
}
data = {"m": "GetSelectionExtent", "state": json.dumps(state)}
select_url_resp = requests.post(f"{base_url}Services/Selection.ashx", data=data)
select_url_resp.raise_for_status()
select_bbox = select_url_resp.json()["extent"]
bbox_dims = [
select_bbox[2] - select_bbox[0],
select_bbox[3] - select_bbox[1],
]
select_bbox_scaled = [
select_bbox[0] - bbox_dims[0] * bbox_scale_factor,
select_bbox[1] - bbox_dims[1] * bbox_scale_factor,
select_bbox[2] + bbox_dims[0] * bbox_scale_factor,
select_bbox[3] + bbox_dims[1] * bbox_scale_factor,
]
state = {
"Application": "GISWEBApp",
"MapTab": "GISWEBMap",
"Level": "",
"Search": "PropertySearch",
"SearchCriteria": {},
"Action": 0,
"TargetLayer": "ParcelsStacked",
"TargetIds": [parcel_id],
"ActiveMapId": parcel_id,
"ActiveDataId": parcel_id,
"Proximity": "",
"SelectionLayer": "",
"SelectionIds": [],
"Query": "ParcelsAll",
"DataTab": "ParcelSummaryInfo",
"MarkupCategory": "MarkupPublic",
"MarkupGroups": [],
"Markup": [],
"FunctionTabs": 63,
"ActiveFunctionTab": 4,
"Extent": {"bbox": select_bbox_scaled},
"VisibleLayers": {
"GISWEBMap": ["AddressLabels", "ParcelLabels", "ParcelsStacked"],
"CritResourcePlan": [
"AddressLabels",
"ParcelLabels",
"ParcelsStacked",
"100YearFloodplain",
"SteepSlopesOverlay",
"WaterProtectionOrdinanceBuffers",
"Y2018ElevationContours100ft",
"Y2018ElevationContours60ft",
"Y2018ElevationContours40ft",
"Y2018ElevationContours20ft",
"Y2018ElevationContours4ft",
],
"Stormwater": [
"AddressLabels",
"ParcelLabels",
"ParcelsStacked",
"StormwaterFacilities",
],
"Zoning": [
"ParcelLabels",
"ParcelsStacked",
"Proffers",
"ZMAswithProffersLabels",
"ZoningClassifications",
"ZoningEntranceCorridors",
"NaturalResourceExtractionOverlay",
"AddressLabels",
],
},
"VisibleTiles": {
"GISWEBMap": ["public_basemap", "public_labels"],
"CritResourcePlan": ["public_basemap", "public_labels"],
"Stormwater": ["public_basemap", "public_labels"],
"Zoning": ["public_basemap", "public_labels"],
},
}
data = {
"m": "MakeMapImage",
"state": json.dumps(state),
"width": 768,
"height": 512,
}
map_url_resp = requests.post(f"{base_url}Services/MapImage.ashx", data=data)
map_url_resp.raise_for_status()
map_url = map_url_resp.content.decode().strip('"')
map_resp = requests.get(f"{base_url}{map_url}")
map_resp.raise_for_status()
with open(out_path, "wb") as fp:
fp.write(map_resp.content)
base_url = "https://gisweb.albemarle.org/gpv_51/"
parcels = fiona.open(
"/Users/joshuacarp/Downloads/parcels_shape_current/Parcels_current.shp"
)
for parcel in parcels[::100]:
bbox = [int(bound) for bound in shape.bounds]
get_map(
base_url,
parcel["properties"]["PIN"],
f"images/{parcel['properties']['PIN']}.png",
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment