How do I enter an "empty" POINT() geometry value into a MySQL field of type POINT?

3.2k views Asked by At

I have a table with a POINT geometry field. I enter latitude/longitude points into it like this:

INSERT INTO table( point )
VALUES( POINT( lon_value, lat_value );

Sometimes I do not have lat/lon values to enter. I am unable to enter a blank, a NULL, or an empty POINT() ... since POINT(0,0) is actually a location on the globe, that won't work either.

What is the solution here?

3

There are 3 answers

3
david strachan On BEST ANSWER

I would use coordinates of North Pole

INSERT INTO table( point )
VALUES( POINT(0.0000,90.0000);

If the actual coordinates of the pole may be an issue i would change the lon value from 0.0000.

0
BrentH On

Since the valid range of latitude in degrees is -90 and +90 for the southern and northern hemisphere respectively; I'm able to switch values to and from NULL by passing in and using 99 (arbitrary out of range number) for Lat comparison like this:

("UPDATE
     tableName SET LatLng = IF(%Lat = 99, NULL, POINT(%Lat, %Lng))
     Where itemID = %itemID"
, array(
     'itemID' => $itemID, 
     'Lat' => $Lat == NULL ? 99 : $Lat,
     'Lng' => $Lng == NULL ? NULL : $Lng 
));
0
xiangyuecn On

Only GeometryCollection supports EMPTY: https://dev.mysql.com/doc/refman/8.0/en/gis-data-formats.html

INSERT INTO table( point )
VALUES( ST_GeomFromText('GEOMETRYCOLLECTION EMPTY') );