Put two layers in the same coordinate system#

To join two layers reliably, start with a known feature from each input. Identify its coordinate values, axis units and declared CRS. If a source CRS is uncertain, resolve it with the data producer before changing it.

Select and label the geometry#

Use set_geometry to select the active geometry column. Use set_crs to label existing coordinates. Replacing a different known label requires allow_override=True and is appropriate when the existing coordinates are already in the stated system.

Choose a target suitable for the join and any distance measurement. SQL ST_Transform requires a Proj-enabled Geometry build, an admitted operation and a literal target SRID. If the build reports missing_capability, see the Proj build and prefix choices in Install Geometry for the interface you use.

Transform and check a control point#

For an EPSG:3857 map, create survey.csv with these contents. Here x is longitude and y is latitude in EPSG:4326.

id,x,y
1,10,20

Transform the point and inspect its SRID and coordinates.

import cugeo.geometry as cg

s = cg.Session()
survey = cg.table_from_file(
    'survey.csv',
    options={
        'geometry': {'type': 'point_xy', 'x': 'x', 'y': 'y'},
        'srid': 4326,
    },
)
query = '''WITH projected AS (
    SELECT id, ST_Transform(ST_GeomFromWKB(geometry), 3857) AS g
    FROM survey
)
SELECT id, ST_SRID(g), ST_X(g), ST_Y(g) FROM projected'''
print(s.sql(query, tables={'survey': survey}).rows)

For ID 1, check for SRID 3857 and coordinates near (1113194.908, 2273030.927) metres. A 3857 label beside values still at (10, 20) would put the point elsewhere on this map. Use the transformed geometry g against the map geometry in the join, and repeat the location and units check with a known non-NULL feature from your layer.

For a regional operation or grid requirement, see Select and reproduce an operation for a region.