Hotdot Cyber
Hotdot Cyber

Reputation: 393

Coordinate type in postgis

Am getting an error when i try to insert data to postgis geometry column.

ERROR: Coordinate values are out of range [-180 -90, 180 90] for GEOGRAPHY type SQL state: 22023

My insert query is.

INSERT INTO meter1(meter_id, meter_no,location,type) 
 VALUES ('M1', 200,ST_GeographyFromText('SRID=3857;  
        POINT(256300.11 9856321.09)'),'automatic' );

Upvotes: 1

Views: 528

Answers (1)

e4c5
e4c5

Reputation: 53734

First of all it looks like one of the situations where you probably don't need to use the geography type.

If your data is geographically compact (contained within a state, county or city), use the geometry type with a Cartesian projection that makes sense with your data.

http://workshops.boundlessgeo.com/postgis-intro/geography.html#why-not-use-geography

Having said that if you need to use the geography type after all you have to accept that geography columns can only save values in degrees and not in meters. Thus you will need to transform your data into a spacial ref sys that supports lat,lng. Thus your query will need to change as follows:

INSERT INTO meter1(meter_id, meter_no,location,type)    
VALUES ('M1', 200,
    ST_Transform(ST_SetSrid(ST_GeomFromText('POINT(256300.11 9856321.09)'), 3587), 4326),
    'automatic' );

The function to use here is ST_Transform

Upvotes: 1

Related Questions