1

I'm trying to get a multiPolgon value returned from an SQL query (SQL Server 2014) to a an Arcpy Geometry Object. I know this is very easy I just am missing something.Whats confusing is this is a Native ESRI Enterprise Geodatabase (ArcGIS 10.7.1) and this is the normal SHAPE field that all feature classes have.

I can do very easily using the Cursor object and the SHAPE@ token associated with the data access module however the query performance on this takes about 4 hours to run due to remote access on very choked pipe. Where as the SQL direct query takes about 30 Seconds to run.

Basically I need the result from SQL Query below for field 4 or 5 or what ever I have to CAST it as to feed into arcpy.Geometry('POLYGON', something from the query)

SELECT
    ITEMS.{feild_0},
    ITEMS.{feild_1},
    ITEMS.{feild_2},
    ITEMS.{feild_3},
    CAST(ITEMS.{feild_4} AS geometry), 
    CAST(ITEMS.{feild_4} AS nvarchar(max)),  
    ITEMS.{feild_6}
FROM
    {user_id}.{table_id} AS ITEMS

WHERE
    {sql_query}
ORDER BY '{feild_0}';
  • 1
    ArcGIS might be able to read the geometry natively, but if not, then you could use Well-Known Text (WKT) or Well-Known Binary (WKB). – Vince Apr 2 '20 at 3:07
  • Which DBMS are you using? – PolyGeo Apr 2 '20 at 3:30
1

So Vince was the one that got me the answer, the return of the nvarchar(max) feeding into the arcpy.FomWKT

SELECT
    ITEMS.{feild_0},
    ITEMS.{feild_1},
    ITEMS.{feild_2},
    ITEMS.{feild_3},
    ITEMS.{feild_4}, 
    CAST(ITEMS.{feild_5} AS nvarchar(max)),  
    ITEMS.{feild_6}
FROM
    {user_id}.{table_id} AS ITEMS

WHERE
    {sql_query}
ORDER BY '{feild_0}';

Pushing the relevant query result

row_geometry = arcpy.FromWKT(row.field_5)

returns <geoprocessing describe geometry object object at 0x000000000A3BE058>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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