Spatial Coordinates Transformer

The SCoordTransformer class takes input data containing a geometry column with geometries and produces a NumPy array containing the centroids of the geometries, which represent the x and y coordinates.

This transformer can be used to pass location information directly to a model.

The main methods of the class are described in the following table.

Method Description
fit Not yet implemented as it does not perform any calculations with the training data.
transform Returns the XY coordinates of the geometries. In case of non-point spatial objects (such as lines and polygons), it returns the centroids of the geometries.
fit_transform Calls the fit and transform methods sequentially with the training data.

See the SCoordTransformer class in Python API Reference for Oracle Spatial AI for more information.

The following example uses the block_groups SpatialDataFrame and the SCoordTransformer class to obtain the centroid’s coordinates from a SpatialDataFrame. The geometries are specified in the geometry column.

from oraclesai.preprocessing import SCoordTransformer 
 
# Define the variables of the training data
X = block_groups[["MEDIAN_INCOME", "MEAN_AGE", "HOUSE_VALUE", "geometry"]] 
 
# Use a referenced coordinate system
X = X.to_crs("epsg:3857") 
 
# Print the given data
print(f">> Original data:\n {X['geometry'].head(5)}")
 
# Transform the data with the SCoordTransformer
coordinates = SCoordTransformer().fit_transform(X) 
 
# Print the transformed data
print(f"\n>> Transformed data:\n {coordinates[:5, :]}")

The resulting output consists of the centroids of the geometries.

>> Original data:
                                             geometry
0  POLYGON ((-13175658.713 4010761.859, -13174935...
1  POLYGON ((-13175749.772 4004714.769, -13174771...
2  POLYGON ((-13179169.173 4002635.119, -13178970...
3  POLYGON ((-13177695.971 4003360.046, -13177503...
4  POLYGON ((-13177368.803 4002939.500, -13176993...

>> Transformed data:
 [[-13174765.1034151    4010231.26409032]
 [-13175173.61624862   4003637.47437617]
 [-13178654.77968995   4002868.5566815 ]
 [-13176298.82436636   4002826.86495246]
 [-13176753.58959072   4002684.55714192]]