I'm currently storing a lot of data on a Azure SQL for Postgres instance. My table consists of columns like lat, lon, and geometry which is created using PostGis function
ST_SetSRID(ST_MakePoint(lat,lon),4326))
However, when I import the table into QGIS using a filter on an identifier column and between two timestamps the QGIS Query Builder clearly shows a decent number of records being returned. However, QGIS (I've tried Google Map, OpenStreetMap) renders the Geometry points near Africa (see screenshot below). Looking at some lat and lon pairs on maps.google.com that make up the geometry points, the location is completely different from what QGIS shows.
I've changed the CRS of the project, the Layers for the Map and the Coordinates (i.e. geometry points) to 4326. But still all the data points show up near Africa.
Any ideas what may be causing this and how to resolve it?
PostGIS convention is to pass longitude first (as X coordinate) and latitude second (as Y). So try
ST_MakePoint(lon, lat, 4326)
Related
I downloaded OpenStreetMap data and uploaded to a local PostgreSQL database with osm2pgsql.
I created a new table as a result of a ST_Union function with only one record (for now).
CREATE TABLE IF NOT EXISTS m_temp.budapest_merge
(
id text COLLATE pg_catalog."default" NOT NULL,
st_union geometry(Polygon,3857),
ter double precision,
CONSTRAINT budapest_merge_pkey PRIMARY KEY (id)
)
Then I checked the area of my polygon.
SELECT ST_Area(st_union) FROM m_temp.budapest_merge
The result was 1151156216.758265 sqm which was weird for me, because I was expecting something around 520 sqkm.
I opened the PostgreSQL layer in QGIS, calculated the area with the Field Calculator tool's $area function.
The result was 526031443.36087507 sqm, which corresponds to my expectation and reality as well.
My question is what can be a problem here?
The QGIS project is in the same projection (EPSG:3857).
Also I know that naming a geometry column st_union is not really nice, but that's not the main concern here.
In Qgis, $area is (if defined), the ellipsoidal area, i.e. the true ground area, while area(geometry) is the planar area, i.e. highly impacted by the geometry projection.
In Postgis, st_area always use the geometry projection, so it is the equialent of QGIS area(geometry).
That being said, 3857 highly distorts distances and areas as you move away from the equator. It is wrong to use this projection for computing distances or areas.
I am new to PostGIS, am not getting the area of polygon right, my sample data is from Google maps, I know the area of the polygon is 11 acres, but the area returned by st_area doesn't match,
I already referred to a few links like below, but unable to resolve the issue, Internet says google follows 4326 Spatial references, I tried a lot, can you please help, Image attached is the polygon from google maps.
I am expecting an array of such coordinates from the user, I have to calculate the area from PostGIS and give an error back to the user if the area entered is not approximated to calculated area.
https://gis.stackexchange.com/questions/169422/how-does-st-area-in-postgis-work
How do I convert a latitude/longitude pair into a PostGIS geography type?
https://gis.stackexchange.com/questions/56862/what-spatial-reference-system-do-i-store-google-maps-lat-lng-in/56925
17.475197 78.389024
17.4771 78.39044
17.475657 78.391652
17.474408 78.390847
17.475197 78.389024
l_polygon_text='MULTIPOLYGON(((
17.4771000000000001 78.3904399999999981,
17.4751970000000014 78.3890240000000063,
17.4756570000000018 78.3916519999999934,
17.4751970000000014 78.3890240000000063,
17.4744080000000004 78.3908469999999937,
17.4771000000000001 78.3904399999999981)))';
st_area(ST_GeometryFromText(l_polygon_text,4326))
st_area(ST_GeometryFromText(l_polygon_text,2163));
st_area(ST_GeometryFromText(l_polygon_text,2249));
st_area(ST_GeometryFromText(l_polygon_text,3859));
ST_AREA(ST_Transform(ST_GeomFromText(l_polygon_text,4326),31467));
ST_Area(ST_Transform(ST_SetSRID(ST_GeomFromText(l_polygon_text),4326),900913));
polygon
In PostGIS, coordinates must be expressed as longitude first, then latitude. Google uses the opposite.
After swapping the coordinates to the proper order, you can't directly call st_area, else you would get an area in "square degrees" which is meaningless. You would have to project to a suitable local coordinate system, or you can use the geography type which will return an area in m2.
select st_area(st_geogFromText('MULTIPOLYGON(((78.3904399999999981 17.4771000000000001, 78.3890240000000063 17.4751970000000014,78.3916519999999934 17.4756570000000018,78.3890240000000063 17.4751970000000014,78.3908469999999937 17.4744080000000004,78.3904399999999981 17.4771000000000001)))'));
st_area
--------------------
26956.897848576307
That being said, the example you have provided is about 6.5 acres, not 11, because the polygon is not properly defined:
I have 2 custom long-lat data sources, one for area polygon, and one for point data as follows:
area polygon data
point data
I tried to map them on tableau using instructions on https://onlinehelp.tableau.com/current/pro/desktop/en-us/maps_dualaxis.htm
, but I cannot get the spread-ed point data on the second layer. all I get is one point.
output
I'm migrating all information in a PostGIS system, with full information about thousands of sport spaces. For all this spaces I got latitude and longitude values, and PostGis need a geometry value for that, this column is already in my table "Location".
The SRID of that application is 23030.
I've looked for how to calculate a geometry value from longitude and latitude, and I find that:
update location set point=ST_GeomFromText('POINT('|| longitud || ' ' || latitud ||')',23030);
UPDATE georrepositorio.geometria SET point = ST_SetSRID(ST_Point( longitud, latitud),23030);
UPDATE georrepositorio.geometria SET POINT = ST_SetSRID(ST_MakePoint(longitud,latitud),23030);
I always get a string like: "0101000020F6590000894327550B97114104EA99EA599D4E41"
In the web application which I am building, if I mark the point to locate the space, it insert in table "location" a string like: "0101000020F659000000000020DFB115C00000008053244240" which looks similar to the string I got using those functions.
The problem is that i can't locate each space because there are so many, so I need a massive migration, and using those function to calculate geometry columns doesn't work. Because ok, those functions calculate a geom value, but when you query the application doesn´t show them.
Anyone knows how to calculate geomtry from latitude and longitude, please? anything
First, the geometries are stored as binary, which you see as "0101000020...", which is called well-known binary (WKB). For POINT geometries, you can extract the coordinate ordinals using ST_X(point) for longitude and ST_Y(point) for latitude. You can also use ST_AsText(point) for a human-readable WKT representation.
EPSG:23030 is a projected spatial reference system (SRS), with eastings and northings with units of metres. But if your coordinate data is degrees of latitude and longitude, you need to use a different SRS, such as EPSG:4326. Once stored correctly, the data can be re-projected for the application using ST_Transform(point, 23030).
This should be quite simple but I am not getting it.
I have a database of locations with lon/lat specified.
After loading the bing map I get the bounds
var view = map.getBounds();
and then call a webmethod to get all the locations which should be shown (within the bounds of the visible map).
I cannot figure out a query to get the locations (which all have a lon/lat specified) .
This obviously does NOT work as when negative values come into play they mess up the query:
SELECT Location_name, longtitude, latitude FROM location_view WHERE latitude< '40.112' and latitude> '35.783' and longtitude< '28.10453' and longtitude> '19.315'
Is there a normalized way to do this? So the comparison would work?
Your query will work absolutely fine with negative values: a longitude of -130 is still west of a longitude of -120. The only situation in which it won't work is if the bounds of your map crosses the 180th meridian. I.e. the "westmost" longitude is 170 and the "eastmost" latitude is -170.
What database are you using? If you're using SQL Server then you can define each of your locations as a Point using the geography datatype. The geography datatype operates on a round model of the earth, so it will account correctly for crossing the 180th meridian with a query like this:
SELECT Location_name
FROM location_view
WHERE location.STIntersects('POLYGON((19.315 35.783, 28.10453 35.783, 28.10453 40.112, 19.315 40.112, 19.315 35.783))') = 1;