Hi, currently i'm working with webmap and i want to find an attributes in the webmap by using GPS coordinate
output expected :
Location: Jalan Jabatan Perhutanan, Keningau, Bahagian Keningau, 89000, Sabah, MYS
KODDUN: N.04, NAMADUN: TANJONG KAPOR
output that i obtaint :
it print out all the attributes instead of the one that match with coordinate.
Location: Jalan Jabatan Perhutanan, Keningau, Bahagian Keningau, 89000, Sabah, MYS
KODDUN: N.04, NAMADUN: TANJONG KAPOR
KODDUN: N.03, NAMADUN: PITAS
KODDUN: N.05, NAMADUN: MATUNGGONG
KODDUN: N.06, NAMADUN: BANDAU
KODDUN: N.09, NAMADUN: TEMPASUK
my code :
from arcgis.gis import GIS
import arcgis
from arcgis.geometry import Geometry
from arcgis.geocoding import reverse_geocode
gis = GIS()
webmap_item_id = "0c7d9a944a5a476694a2f998d53e3e1e"
webmap_item = gis.content.get(webmap_item_id)
webmap_data = webmap_item.get_data()
longitude = 116.157966
latitude = 5.341622
given_coord = {'x': longitude, 'y': latitude, "spatialReference": {"wkid": 4326}}
point_geom = Geometry(given_coord)
location_details = reverse_geocode([longitude, latitude])
place_name = location_details.get('address', {}).get('LongLabel', 'Unknown Location')
print(f"Location: {place_name}")
if 'operationalLayers' in webmap_data:
for layer in webmap_data['operationalLayers']:
if 'featureCollection' in layer:
for layer_collection in layer['featureCollection']['layers']:
for feature in layer_collection['featureSet']['features']:
attributes = feature['attributes']
geometry = feature['geometry']
koddun = attributes.get("KODDUN")
namadun = attributes.get("NAMADUN")
parlimen = attributes.get("PARLIMEN")
# Fetch GPS coordinates
if 'x' in geometry and 'y' in geometry:
longitude = geometry['x']
latitude = geometry['y']
print(f"KODDUN: {koddun}, NAMADUN: {namadun}, PARLIMEN: {parlimen}")
else:
print(f"KODDUN: {koddun}, NAMADUN: {namadun}")
hope someone can help me because this is my first time using API