st_asText st_지옥 이야기

11311 단어 MySQL
mysql8에서 spatial index를 유효하게 하기 위해 SRID를 통일해야 한다면 - Qiita의 후속

인근 검색


'어느 지점에서 반경 2km 이내의 곳을 조사하고 싶다'는 간단한 검색으로 만들어진 조회입니다.
SELECT count(*) FROM locations WHERE 
ST_Within(
    location,
    ST_GeomFromText(
        St_AsText(
            ST_Buffer(
                ST_GeomFromText(
                    St_AsText(
                        ST_GeomFromText('POINT(43.76747 142.297905)' , 4326)
                    )
                ),
                2000 * 180.0 / 3.141592653589793 / 6378137.0
            )
        )
    ,4326)
);
이렇게 웃어.
st_geomFromText st_asText st_geomFromText st_asText st_geomFromText st_asText st_geomFromText
- 2ch 전체 AA 일러스트레이션 계획
여기 쓰려고 했는데
SELECT count(*) FROM locations WHERE 
ST_Within(
    location,
    ST_Buffer(
        ST_GeomFromText('POINT(43.76747 142.297905)' , 4326),
        2000 * 180.0 / 3.141592653589793 / 6378137.0
    )
);
SQL   : #22S00st_buffer(POINT, ...) has not been implemented for geographic spatial reference systems.
괘씸하다
“st_버퍼는 지오그래픽 SRS를 위해 만든 것이 아니기 때문에 여기서 조금만 참아라.
SELECT count(*) FROM locations WHERE 
ST_Within(
    location,
    ST_Buffer(
        ST_GeomFromText(
            St_AsText(
                ST_GeomFromText('POINT(43.76747 142.297905)' , 4326)
            )
        ),
        2000 * 180.0 / 3.141592653589793 / 6378137.0
    )
);
SQL   : #HY000The SRID of the geometry does not match the SRID of the column 'location'. The SRID of the geometry is 0, but the SRID of the column is 4326. Consider changing the SRID of the geometry or the SRID property of the column.
부드럽다

왜 이렇게 됐을까요?


공간 관계 함수와 공간 연산자 함수의 차이.
ST_Buffer에 포함된 공간 산자 함수는 다음과 같습니다.
12.16.8 Spatial Operator Functions
OpenGIS proposes a number of functions that can produce geometries. They are designed to implement spatial operators.
These functions support all argument type combinations except those that are inapplicable according to the Open Geospatial Consortium specification.
Unless otherwise specified, functions in this section handle their arguments as follows:
  • If any argument is NULL, the return value is NULL.
  • If any geometry argument is not a syntactically well-formed geometry, an ER_GIS_INVALID_DATA error occurs.
  • If any geometry argument has an SRID value that refers to an undefined spatial reference system (SRS), an ER_SRS_NOT_FOUND error occurs.
  • For functions that take multiple geometry arguments, if those arguments do not have the same SRID, an ER_GIS_DIFFERENT_SRIDS error occurs.
  • If any geometry argument has an SRID value for a geographic SRS, an ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS error occurs.
  • Otherwise, the return value is non-NULL.
  • MySQL :: MySQL 8.0 Reference Manual :: 12.16.8 Spatial Operator Functions
    이에 맞서, ST_within 공간 관계 함수
    12.16.9.1 Spatial Relation Functions That Use Object Shapes
    The OpenGIS specification defines the following functions to test the relationship between two geometry values g1 and g2, using precise object shapes. The return values 1 and 0 indicate true and false, respectively, except for ST_Distance(), which returns distance values.
    Functions in this section detect arguments in either Cartesian or geographic spatial reference systems (SRSs), and return results appropriate to the SRS.
    Unless otherwise specified, functions in this section handle their arguments as follows:
  • If any argument is NULL or any geometry argument is an empty geometry, the return value is NULL.
  • If any geometry argument is not a syntactically well-formed geometry, an ER_GIS_INVALID_DATA error occurs.
  • If any geometry argument refers to an undefined spatial reference system (SRS), an ER_SRS_NOT_FOUND error occurs.
  • For functions that take multiple geometry arguments, if those arguments do not have the same SRID, an ER_GIS_DIFFERENT_SRIDS error occurs.
  • If any geometry argument is geometrically invalid, either the result is true or false (it is undefined which), or an error occurs.
  • For geographic SRS geometry arguments, if any argument has a longitude or latitude that is out of range, an error occurs:
  • If a longitude value is not in the range (−180, 180], an ER_LONGITUDE_OUT_OF_RANGE error occurs.
  • If a latitude value is not in the range [−90, 90], an ER_LATITUDE_OUT_OF_RANGE error occurs.
  • Ranges shown are in degrees. If an SRS uses another unit, the range uses the corresponding values in its unit. The exact range limits deviate slightly due to floating-point arithmetic.
  • Otherwise, the return value is non-NULL.
  • These object-shape functions are available for testing
    아, 이거 지오그래피형과 지오메트리형이죠?
    지물형이라는 게 있어요. - Qiita.

    자꾸 이해가 가요.


    공간계의 함수 중에는 직행(피리칼) 좌표계를 전제로 하는 함수와 지리 좌표계를 전제로 하는 함수가 있는데 둘 다 가능하다.
  • st_버퍼는 정교 좌표계의 값을 받아들여 정교 좌표계의 결과를 되돌려준다
  • st_within은 두 매개변수의 SRID가 같아야 합니다
  • .
    따라서 원점POINT(43.76747 142.297905)#srid:4326을 st_버퍼한테 먹으라고.
    ST_GeomFromText(
        St_AsText(
            ST_GeomFromText('POINT(43.76747 142.297905)' , 4326)
        )
    )
    
    SRID를 이렇게 제거할 필요가 있습니다.
    또한 ST_within을 먹기 위해서는 첫 번째 파라미터인 location의 SRID4326에 맞춰야 한다
    ST_GeomFromText(
        St_AsText(ST_Buffer(<>))
    ,4326)
    
    SRID4326으로 돌아가야 합니다.

    왠지 결과가


    나는 정교 좌표계와 지리 좌표계에서 같은geometry형을 사용하는 것이 번거로운 원인이라고 생각한다.

    좋은 웹페이지 즐겨찾기