ST_NumGeometries()
.SELECT "SHAPE".ST_NumGeometries() FROM "TESTGEO"."continent" WHERE CONTINENT='Europe';
--The result is 296
SET SCHEMA TESTGEO;
DROP PROCEDURE "TESTGEO"."CONTINENT_MAINLAND_CENTER_GEOJSON";
CREATE PROCEDURE "TESTGEO"."CONTINENT_MAINLAND_CENTER_GEOJSON"
(IN continent_name NVARCHAR (20), OUT nr_shapes INT, OUT mainland CLOB, OUT point_centroid CLOB, OUT point_middle CLOB)
LANGUAGE SQLSCRIPT
READS SQL DATA
AS
whole_continet ST_GEOMETRY;
BEGIN
DECLARE single_shape, theshape, temp_shape ST_GEOMETRY;
DECLARE shape_area, shapei_area DECIMAL = 0;
DECLARE i INTEGER;
select "SHAPE" into whole_continet FROM "TESTGEO"."continent" WHERE CONTINENT=:continent_name;
nr_shapes := whole_continet.ST_NumGeometries();
FOR i IN 1..nr_shapes DO
single_shape := :whole_continet.ST_GeometryN(i);
shapei_area := single_shape.ST_Area();
IF shape_area < shapei_area
THEN
shape_area := shapei_area;
theshape := single_shape;
END IF;
END FOR;
--Mainland shape as a GeoJSON
mainland := theshape.st_asGeoJSON();
--Calculate centroid
temp_shape := theshape.ST_Centroid();
point_centroid := temp_shape.st_asGeoJSON();
--Calculate midpoint
temp_shape := theshape.ST_Envelope();
temp_shape := temp_shape.ST_Centroid();
point_middle := temp_shape.st_asGeoJSON();
END;
Europe
as a parameter.CALL "TESTGEO"."CONTINENT_MAINLAND_CENTER_GEOJSON"(
CONTINENT_NAME => 'Europe',
NR_SHAPES => ?,
MAINLAND => ?,
POINT_CENTROID => ?,
POINT_MIDDLE => ?
);
This and other exercises were part of the very first SAP CodeJam on the topic of professing geospatial data with SAP HANA in Walldorf, Germany. I'd like to thank as well markus.fath and christian.schuetz from SAP HQ office joining to share some more real life use cases and demos of SAP HANA geospatial processing capabilities!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
21 | |
18 | |
11 | |
10 | |
9 | |
9 | |
7 | |
7 | |
5 | |
5 |