0

The OSMQuery tool (https://github.com/riccardoklinger/OSMquery/releases/tag/1.0.0) makes a request to Overpass API and returns a layer. The in_query makes the request to the Overpass API and must be written in Overpass QL. It is to be passed like a code block. So with """code""". I like to have the queries generated by algorithm in a later step. For this I need to be able to exchange elements of the query.

Does anyone have an idea how I can achieve this using ArcPy with ArcGIS Pro?

As the script stands it does not work. For it to work #2 must be selected. But this option is static and not dynamic.

import arcpy

arcpy.ImportToolbox(r"C:\Arbeitsordner\OSMquery-1.0.0\OSMquery-1.0.0\OSMQuery.pyt")

arcpy.env.workspace = "C:/Users/user/Documents/ArcGIS/Projects/BraunDaten/Default.gdb"
#tabelle = "Straßenverzeichnis_osmST_Braunschweig"

#Feld "shape_length" hinzufügen
#arcpy.management.AddField(tabelle, "shape_length", "DOUBLE")

ags_name = "Braunschweig"
str_name = "Celler Heerstraße"
plz = "38114"

semi= """"""
ags_f = f"(area[name={ags_name}];) ->.a;"
plz_f = f"(area[postal_code={plz}];) ->.b;"
str_f = f"way(area.a)(area.b)[name={str_name}];"
in_query = semi + ags_f + plz_f + str_f + semi
# in_query = "\'" + "\'" + "\'" + ags_f + plz_f + str_f + "\'" + "\'" +"\'"

#1: in_query = f"(area[name={ags_name}];) ->.a;(area[postal_code={plz}];) ->.b;way(area.a)(area.b)[name={str_name}];"
#2: in_query = """(area[name="Braunschweig"];) ->.a;(area[postal_code="38114"];) ->.b;way(area.a)(area.b)[name="Celler Heerstraße"];"""
#3: in_query = f"""(area[name={ags_name}];) ->.a;(area[postal_code={plz}];) ->.b;way(area.a)(area.b)[name={str_name}];"""


arcpy.OSMQueryToolbox.GetOSMDataExpert(in_query)
0

1 Answer 1

0

The problem was the query. It works totally fine with f-strings. The right query is

in_query = f"""(area[name="{ags_name}"];) ->.a;(area[postal_code="{plz}"];) ->.b;way(area.a)(area.b)[name="{str_name}"];"""

I just forgot the " before and after the key value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.