I'm using Psycopg2 and PostgreSQL to try and isolate points from within polygons for ArcGIS. I generate a spatial condition from coordinates and can then pull all the points within that spatial condition using ST_Within.
If I have two spatial conditions and try and run this SQL query:
# Combine both spatial conditions using AND in the SQL query combined_spatial_condition = f"{catch_cond} AND {spatial_condition}" # Construct the SQL query sql_query = f"SELECT \"Date\", lai, lai2, lai3, fcover, \"Latitude\", \"Longitude\" FROM sdplus_good WHERE {combined_spatial_condition};" I get all the points within {spatial_condition} what want is all the point that are in both {catch_cond} AND {spatial_condition}, and only those points.
If i run
sql_query2 = f"SELECT \"Date\", lai , lai2, lai3, fcover ,\"Latitude\", \"Longitude\" FROM sdplus_good WHERE {spatial_condition};" sql_query3 = f"SELECT \"Date\", lai , lai2, lai3, fcover ,\"Latitude\", \"Longitude\" FROM sdplus_good WHERE {catch_cond};" independently I get the correct set of points, so how do I run one SQL query to give the correct set?
f"({catch_cond}) AND ({spatial_condition})"