geom format in postGIS use to print in google maps android - postgresql

a greeting, a friend happened to me a route of transportation and I step in the following format:
0102000020E610000049020000F2D077B7B23A53C0F03504C7651428C07E703E75AC3A53C07E37DDB2431428C07E8AE3C...
He told me it was a MultiLineString. I used the PostGIS function:
SELECT St_asewkt ('0102000020E6100000810200 .....');
with this i supposedly should be able to get the wkt format that I can
get the coordinates and use it on google maps api to paint a path in android, but when using it throws me empty. Help me please
I need to get something like MULTILINESTRING((0 0,1 1,1 2),(2 3,3 2,5 4)) ... to get lat lng coordinates to paint it in google maps api with android.
To summarize what I have is this value
0102000020E6100000810200 ..... and would like to paint it in android with google maps api, that's why I try to get the coordinates that function.

What you have is Well know binary, WKB, which is explained on this page along with its companion well known text (WKT), but in an ASCII (hex) representation, see the docs
If you do something like:
select st_setsrid(st_makepoint(50, -2),4326);
you will see 0101000020E6100000000000000000494000000000000000C0, similar to what you have.
You can insert these directly into a db with
create table test (g geometry);
insert into test(g) values(ST_GeomFromEWKB(E'\\x0101000020E6100000000000000000494000000000000000C0')
where the E'\\x indicates that you are inserted a hex string, see binary format docs.
If you now do
select g from test;
you will get your WKB back and if you do
select st_astext(g) from test;
you will see the more human-readable WKT format.
The best way to load data in the correct format is to use:
COPY table_name FROM your_file.csv CSV;
where your wkb would be, as is, unquoted, in the your_file.csv.

Related

Using the toInteger function with locale and format parameters

I've got a dataflow with a csv file as source. The column NewPositive is a string and it contains numbers formatted in European style with a dot as thousand seperator e.g 1.019 meaning 1019
If I use the function toInteger to convert my NewPositive column to an int via toInteger(NewPositive,'#.###','de'), I only get the thousand cipher e.g 1 for 1.019 and not the rest. Why? For testing I tried creating a constant column: toInteger('1.019','#.###','de') and it gives 1019 as expected. So why does the function not work for my column? The column is trimmed and if I compare the first value with equality function: equals('1.019',NewPositive) returns true.
Please note: I know it's very easy to create a workaround by toInteger(replace(NewPositive,'.','')), but I want to learn how to use the toInteger function with the locale and format parameters.
Here is sample data:
Dato;NewPositive
2021-08-20;1.234
2021-08-21;1.789
I was able to repro this and probably looks to be a bug to me . I have reported this to the ADF team , will let you know once I hear back from them . You already have a work around please go ahead that to unblock yourself .

my result does not show the result in geometry image

my pgAdmin4 does not show me the output in image despite the postgis extension is enabled. Here is the result as a case.
POLYGON((1.337060775394912 -1.111140466039209,1.152240934977428 -0.765366864730185,1.03842943919354 -0.390180644032262,1 -6.462170208665352e-15,1.038429439193538 0.39018064403225,1.152240934977424 0.765366864730173,1.337060775394905 1.111140466039198,1.5 1.309682485677078,1.662939224605084 1.111140466039215,1.847759065022569 0.765366864730191,1.961570560806458 0.39018064403227,2 0,1.961570560806461 -0.390180644032256,1.847759065022574 -0.765366864730179,1.662939224605091 -1.111140466039204,1.5 -1.309682485677078,1.337060775394912 -1.111140466039209))
Is your geometry stored in a geometry or geography type column? What you show in your question is a WKT (Well Known Text) representation of a polygon, not the polygon itself in the "PostgreSQL format". This is how your polygon should look like in order for you to plot it in the Geometry Viewer:
0103000020E61000000100000011000000685EF1D69964F53FDD68AE393BC7F1BFC172CD30946FF23F94A9AEA6E27DE8BF54A30830689DF03F6DA6693CB8F8D8BF000000000000F03F00000000601AFDBC4BA30830689DF03F95A5693CB8F8D83FAF72CD30946FF23F28A9AEA6E27DE83F495EF1D69964F53FAB68AE393BC7F13F000000000000F83F5908429F75F4F43F86A10E29669BFA3FF868AE393BC7F13F328D32CF6B90FD3FCAA9AEA6E27DE83FA35CF7CF9762FF3FFDA6693CB8F8D83F00000000000000400000000000000000B15CF7CF9762FF3F01A6693CB8F8D8BF488D32CF6B90FD3F5EA9AEA6E27DE8BFA5A10E29669BFA3FC668AE393BC7F1BF000000000000F83F5908429F75F4F4BF685EF1D69964F53FDD68AE393BC7F1BF
See it for yourself:
Note: For visuailisation purposes, I took the liberty of adding the reference system 4326 (WGS84). The casting from WKT to geometry is in the end of the statement as ::geometry
SELECT 'SRID=4326;POLYGON((1.337060775394912 -1.111140466039209,1.152240934977428 -0.765366864730185,1.03842943919354 -0.390180644032262,1 -6.462170208665352e-15,1.038429439193538 0.39018064403225,1.152240934977424 0.765366864730173,1.337060775394905 1.111140466039198,1.5 1.309682485677078,1.662939224605084 1.111140466039215,1.847759065022569 0.765366864730191,1.961570560806458 0.39018064403227,2 0,1.961570560806461 -0.390180644032256,1.847759065022574 -0.765366864730179,1.662939224605091 -1.111140466039204,1.5 -1.309682485677078,1.337060775394912 -1.111140466039209))'::geometry

PostGIS - Route matching solution

We are building an application where I am a driver and i travel from point A to point B.On my way i can find passengers who travel in the same route.
We are using PostgreSQL with PostGIS extension.
After googling a lot i have found out that we can use linestring to achieve this.I am not fully sure whether this approach will work out.
Suppose I have co-ordinates of my source and destination.
var RouteCoordinates = [
{lat: 37.772, lng: -122.214},
{lat: 21.291, lng: -157.821},
{lat: -18.142, lng: 178.431},
{lat: -27.467, lng: 153.027}
];
I need to store this as linestring in my DB.
After stroring if a passenger is also going in this route but as we know his source and destination wont be exactly in my line string but they will be near.
For example around 1km radius
As you can see my source and destination is that line. And as I am travelling I want to pick all those whose (source and destination) are near to my routes (within particular radius)
If I want to find particular location in my DB within particular radius I will be querying like this
SELECT id, name, address, geom
FROM Seattle_Starbucks
WHERE ST_DWithin(geom, ST_MakePoint(-122.325959,47.625138)::geography, 1000);
Now I can achieve my solution as I am new to postGIS its little bit confusing
How to store all all my source and destination point in DB
ANS: I need to convert in to linestring using this function ST_MakeLine and then store, right?
How to query that based on my requirement as I have mentioned above
Can you please give me the insight on how to achieve this. Your help is greatly appreciated. Thanks
A few thougths on your question:
I need to convert in to linestring using this function ST_MakeLine and
then store, right?
Yes, to merge multiple points into a LINESTRING you can use ST_MakeLine:
SELECT ST_AsText(
ST_MakeLine(ARRAY[ST_MakePoint(-122.21,37.77),
ST_MakePoint(-157.82,21.29),
ST_MakePoint(178.43,-18.14),
ST_MakePoint(153.02,-27.46)]));
st_astext
---------------------------------------------------------------------
LINESTRING(-122.21 37.77,-157.82 21.29,178.43 -18.14,153.02 -27.46)
(1 Zeile)
How to query that based on my requirement as I have mentioned above
Create a buffer on each point of your LINESTRING and check wether other geometries are inside of it.
First, you have to split your rout LINESTRING into POINTs using ST_DumpPoints ...
db=# SELECT ST_AsText((ST_DumpPoints('LINESTRING(-122.21 37.77,-157.82 21.29,178.43 -18.14,153.02 -27.46)'::GEOMETRY)).geom);
st_astext
----------------------
POINT(-122.21 37.77)
POINT(-157.82 21.29)
POINT(178.43 -18.14)
POINT(153.02 -27.46)
(4 Zeilen)
.. and then use ST_Buffer to create a buffer around each point. ST_Buffer returns a geometry with the area surrounding your point (or any other geometry type). For instance, taking the first point of your route (if I didn't switch x and y, it's somewhere in San Francisco) POINT(-122.21 37.76):
db=# SELECT ST_AsText(
ST_Buffer('POINT(-122.21 37.76)'::GEOMETRY,0.0001, 'quad_segs=16'));
Returns this geometry:
POLYGON((-122.2099 37.76,-122.209900481527 37.759990198286,-122.209901921472 37.7599804909678,-122.209904305966 37.7599709715323,-122.209907612047 37.7599617316568,-122.209911807874 37.7599528603263,-122.209916853039 37.7599444429767,-122.209922698955 37.7599365606716,-122.209929289322 37.7599292893219,-122.209936560672 37.7599226989547,-122.209944442977 37.7599168530388,-122.209952860326 37.7599118078736,-122.209961731657 37.7599076120467,-122.209970971532 37.7599043059664,-122.209980490968 37.759901921472,-122.209990198286 37.7599004815273,-122.21 37.7599,-122.210009801714 37.7599004815273,-122.210019509032 37.759901921472,-122.210029028468 37.7599043059664,-122.210038268343 37.7599076120467,-122.210047139674 37.7599118078736,-122.210055557023 37.7599168530388,-122.210063439328 37.7599226989547,-122.210070710678 37.7599292893219,-122.210077301045 37.7599365606716,-122.210083146961 37.7599444429767,-122.210088192126 37.7599528603263,-122.210092387953 37.7599617316568,-122.210095694034 37.7599709715323,-122.210098078528 37.7599804909678,-122.210099518473 37.759990198286,-122.2101 37.76,-122.210099518473 37.760009801714,-122.210098078528 37.7600195090322,-122.210095694034 37.7600290284677,-122.210092387953 37.7600382683432,-122.210088192126 37.7600471396737,-122.210083146961 37.7600555570233,-122.210077301045 37.7600634393284,-122.210070710678 37.7600707106781,-122.210063439328 37.7600773010453,-122.210055557023 37.7600831469612,-122.210047139674 37.7600881921264,-122.210038268343 37.7600923879533,-122.210029028468 37.7600956940336,-122.210019509032 37.760098078528,-122.210009801714 37.7600995184727,-122.21 37.7601,-122.209990198286 37.7600995184727,-122.209980490968 37.760098078528,-122.209970971532 37.7600956940336,-122.209961731657 37.7600923879533,-122.209952860326 37.7600881921264,-122.209944442977 37.7600831469612,-122.209936560672 37.7600773010453,-122.209929289322 37.7600707106781,-122.209922698955 37.7600634393284,-122.209916853039 37.7600555570233,-122.209911807874 37.7600471396737,-122.209907612047 37.7600382683432,-122.209904305966 37.7600290284677,-122.209901921472 37.7600195090322,-122.209900481527 37.760009801714,-122.2099 37.76))
If you're wondering about the shape of this buffer, please read this answer.
And using this query you can check if another geometry is inside of this buffer (ST_Within):
db=# SELECT
ST_Within('POINT(-122.21 37.76)'::GEOMETRY,
ST_Buffer('POINT(-122.21 37.76)'::GEOMETRY,0.0001, 'quad_segs=16'));
st_within
-----------
t
(1 Zeile)
To put it all together, you can use a CTE (aka WITH clause) and write something like this:
WITH j AS (
SELECT
(ST_DumpPoints('LINESTRING(-122.21 37.77,-157.82 21.29,178.43 -18.14,153.02 -27.46)'::GEOMETRY)).geom AS g)
SELECT id, name, address, geom
FROM Seattle_Starbucks
WHERE ST_Within(geom,ST_Buffer(j.g,0.0001, 'quad_segs=16'))

GreenPlum Substring - Getting part of a long text

say I have a long URL
xyz = 'www.google.com/xyz?para1=value1&para2=value2&para3=value3....'
I am trying to get the 'para1' out of this long URL
So, I have
select TRIM(Leading '?' from Substring(xyz from '%#"?%=#"%' for '#'))
The answer I get for this particular statement is
para1=value1&para2=value2&para3=
How can I get just 'para1' using the select statement above (or any other similar method?)
I am using Greenplum (as mentioned in the topic heading)
Since you apparently have the regexp_ functions (I didn't think Greenplum supported them) use:
select (regexp_matches(
'www.google.com/xyz?para1=value1&para2=value2&para3=value3....',
'\?([^&]+)='
))[1];

postgis shape file import problems

Hi I'm trying to import a shape file from
http://www.nyc.gov/html/dcp/html/bytes/bytesarchive.shtml
into a postgis database. the above files creates MULTIPOLYGONS when i import using shp2pgsql.
then i'm trying to simply determine if lat/long points are contained in my multipolygons
however my select's are not working, and when i print out the poitns of my the_geom column it seems to be very broken.
select st_astext(geom) from (select (st_dumppoints(the_geom)).* from nybb where borocode =1) foo;
gives the result...
st_astext
------------------------------------------
POINT(1007193.83859999 257820.786899999)
POINT(1007209.40620001 257829.435100004)
POINT(1007244.8654 257833.326199993)
POINT(1007283.3496 257839.812399998)
POINT(1007299.3502 257851.488900006)
POINT(1007320.1081 257869.218500003)
POINT(1007356.64669999 257891.055800006)
POINT(1007385.6197 257901.432999998)
POINT(1007421.94509999 257894.084000006)
POINT(1007516.85959999 257890.406100005)
POINT(1007582.59110001 257884.7861)
POINT(1007639.02150001 257877.217199996)
POINT(1007701.29170001 257872.893099993)
...
for points in nyc, this is very off.. what am i doing wrong?
The points are not of. The spatial data that is referred to is NOT in lat/long. This is why numbers are different from what you expect. If you need it to be in long/lat it must be reprojected. See more here: http://postgis.refractions.net/news/20020108/
The projection of the data seems to be in the NAD_1983_StatePlane_New_York_Long_Island_FIPS_3104_Feet coordinate system (according to the metadata - see code.).
<spref>
<horizsys>
<planar>
<planci>
<plance Sync="TRUE">coordinate pair</plance>
<coordrep>
<absres Sync="TRUE">0.000000</absres>
<ordres Sync="TRUE">0.000000</ordres>
</coordrep>
<plandu Sync="TRUE">survey feet</plandu>
</planci>
<mapproj><mapprojn Sync="TRUE">Lambert Conformal Conic</mapprojn><lambertc><stdparll Sync="TRUE">40.666667</stdparll><stdparll Sync="TRUE">41.033333</stdparll><longcm Sync="TRUE">-74.000000</longcm><latprjo Sync="TRUE">40.166667</latprjo><feast Sync="TRUE">984250.000000</feast><fnorth Sync="TRUE">0.000000</fnorth></lambertc></mapproj></planar>
<geodetic>
<horizdn Sync="TRUE">North American Datum of 1983</horizdn>
<ellips Sync="TRUE">Geodetic Reference System 80</ellips>
<semiaxis Sync="TRUE">6378137.000000</semiaxis>
<denflat Sync="TRUE">298.257222</denflat>
</geodetic>
<cordsysn>
<geogcsn Sync="TRUE">GCS_North_American_1983</geogcsn>
<projcsn Sync="TRUE">NAD_1983_StatePlane_New_York_Long_Island_FIPS_3104_Feet</projcsn>
</cordsysn>
</horizsys>
</spref>
If you work much with spatial data I suggest that you read more about map projection.
I think this is not issue with PostGIS. I checked input esri Shape file nybb.shp with AvisMap Free Viewer and as you see points are weird itself:
However there is something interesting in nybb.shp.xml metadata file:
<spdom>
<bounding>
<westbc Sync="TRUE">-74.257465</westbc>
<eastbc Sync="TRUE">-73.699450</eastbc>
<northbc Sync="TRUE">40.915808</northbc>
<southbc Sync="TRUE">40.495805</southbc>
</bounding>
<lboundng>
<leftbc Sync="TRUE">913090.770096</leftbc>
<rightbc Sync="TRUE">1067317.219904</rightbc>
<bottombc Sync="TRUE">120053.526313</bottombc>
<topbc Sync="TRUE">272932.050103</topbc>
</lboundng>
</spdom>
I am not familiar with those toolkit (ESRI ArcCatalog), but most probably you need to rescale your points after import using that metadata.