0

I am setting up a Geometry Collection in a MySql database. I have added various geometry classes thus:

SET @g ='GEOMETRYCOLLECTION(POINT(1 1),LINESTRING(0 1,2 3,4 5), POINT(6 6))'; INSERT INTO myTable (geoCollectionField) VALUES (GeomFromText(@g));

The geoCollectionField responds as expected in the WKT formay:

GEOMETRYCOLLECTION(POINT(1 1),LINESTRING(0 1,2 3,4 5),POINT(6 6))

I can fetch the data from this Geometry Collection in several ways.

SELECT geoCollectionField FROM myTable;

gives the complete GEOMETRYCOLLECTION(POINT(1 1),LINESTRING...

SELECT AsText(GeometryN(geoCollectionField, 1)) FROM myTable;

gives the indexed geometry class POINT(1 1).

I have not been able to write a SELECT that fetches only one class type, for example the POINT classes to end up with POINT((1 1),(6 6)).

Any thoughts?

4

1 回答 1

0

考虑以下步骤:

  1. 获取您使用的几何图形数量STNumGeometries ReferenceGeometryCollectionSTNumGeometries
  2. 使用循环遍历GeometryCollection.
  3. 使用(STGeometryN Reference)获取特定索引处的几何图形STGeometryN
  4. 对于每个几何,使用(STGeometryType Reference)获取几何类型STGeometryType
  5. 检查几何类型是否与您所需的类型匹配。如果您有匹配项,您可能希望将其添加到结果GeometryCollection中。

遵循这些步骤将导致

GEOMETRYCOLLECTION(POINT(1 1), POINT(6 6))

您还可以根据所需的几何类型(MultiPoint, MultiLineString, MultiPolygon)使用其他集合

多点结果可能如下所示:

MULTIPOINT((1 1), (6 6))
于 2016-08-31T18:19:15.667 回答