I have a mysql table containing polygons some of which are open and I need to close them. Presumably by appending the "StartPoint" to the end of the "Linestring" and rewriting as a polygon. Any ideas?
Sure I can grab out and test a polygon to see if its open or closed with
SELECT ExteriorRing(SHAPE) into #testshape from tablename where OGR_FID=1;
SELECT (StartPoint(#testshape)) INTO #SP;
SELECT (EndPoint(#testshape)) INTO #EP;
SELECT #EP=#SP as myIsRing;
ok fine but when it's open I need to append the Startpoint to the end of the line string in order to close the polygon. Is there a way to append that "closure" point and create a closed polygon?
Might be worth noting that I tried (as per the man page)
SELECT UNION(#testshape,#SP) INTO #newshape;
And got the standard syntax error ERROR 1064 (42000) as though my version didnt accept the UNION function.
Sorry everyone, Threw a couple more hours at the problem and got the following
select polygon(geomfromtext(astext(concat(geomfromtext(astext(#testshape)),(geomfromtext(astext(#SP))))))) INTO #newpoly;
Not exactly clean but it worked and can be tested with:
SELECT (StartPoint(EXTERIORRING(#newpoly))) INTO #SP2;
SELECT (EndPoint(EXTERIORRING(#newpoly))) INTO #EP2;
SELECT #EP2=#SP2 as myIsRing;
Related
I have been trying out the following query in MySQL Workbench:
SELECT NAME,LEAD,OUTCOME,COUNT(*) AS NUMBER_OUTCOME
FROM OUTCOMES_BY_USER
ORDER by NAME,LEAD,OUTCOME ASC;
However I am getting this error:
"SELECT" is not valid at this position for this server version, expecting '(' with
I have tried to find out where the error is coming from by taking away parts of the query and seeing where it breaks, it seems to work when I try:
SELECT NAME
FROM OUTCOMES_BY_USER;
However when I add in another column (as shown below) I start getting the same error:
SELECT NAME, LEAD
FROM OUTCOMES_BY_USER;
I am really not sure how to get around this error, I was trying this query in sqlfiddle and it worked fine, however my sqlfiddle suddenly stopped working and the website just flat out wont build schemas for me anymore. so I tried it out on a my universities MySQL server and have been getting this error. Please help!
LEAD() is a MySQL function, hence it is a reserved word. You can add backticks around reserved table or column names to bypass this error :
SELECT NAME,`LEAD`,OUTCOME,COUNT(*) AS NUMBER_OUTCOME
FROM OUTCOMES_BY_USER
ORDER by NAME,`LEAD`,OUTCOME ASC;
I am looking for a solution for finding wether a LAT,LNG Point is contained inside any Polygon in my MySQL table.
For some reason that extends past my SQL knowledge, my queries using ST_Intersects returning 'Function not found'. So i have stried in it's place:
SELECT `area_title` FROM `service_areas` WHERE MBRIntersects(`area_poly`, GEOMFROMTEXT('POINT(40.775032, -73.970778)'));
My table for testing is fairly simply and stores a
1. area_poly GEOMETRY stores POLYGON((-71.740723 41.360319,-71.685791 42.106374,-71.71875 42.407235,-71.905518 42.771211,-72.070312 43.036776,-72.432861 43.157109,-72.718506 43.397065,-73.190918 43.55651,-73.619385 43.580391,-74.32251 43.572432,-75.201416 43.277205,-75.717773 43.004647,-75.926514 42.795401,-76.135254 42.528796,-76.256103 42.138968,-76.289062 41.869561,-76.234131 41.442726,-76.190185 40.955011,-75.992432 40.472024,-75.849609 40.153687,-75.629883 39.783213,-75.311279 39.529467,-74.94873 39.368279,-74.520264 39.257778,-74.256592 39.478606,-71.5979 40.971604,-71.740723 41.360319))
And
2. area_title VARCHAR(20) stores service area 1
I am trying to pass a Point as POINT(40.775032, -73.970778) as shown above.
Expected result would be to return any area_title's that the point is within it's polygon; However, my query returns 0 Rows.
I know there are a ton of questions/answers on slack and the web, but i have not found a solution trying most of the methods. With my lack of SQL knowledge i'm not sure if i'm storing the Poly correctly or not using the correct function to find it.
Any help, even pointing in the right direction is appreciated.
A simple solution for anyone who is running into the same issue:
SELECT ea.name, ea.area_poly from service_areas as ea WHERE contains(ea.area_poly, GeomFromText(AsText(point(#lat, #lng)), 4326))
My polygon ea.area_poly is saved as Polygon((lat1 lng1,lat2 lng2, etc..)) as a geometry type in SQL.
I have Query :
SELECT ST_PolygonFromText(CONCAT('Polygon((',DATA_GPS,'))'))
FROM TABLE_A
CROS JOIN TABLE_B
Show error :
Data truncation: Invalid GIS data provided to function st_geometryfromtext.
Error at line 8 because first and last gps not equal or not close polygon.
show like this :
Polygon((107.15778031165127 -6.304745648974358 107.15945401007279 -6.304639009497479 107.15949692542361 -6.307624906559413))
How to query to exclude not close polygon like that ?
Thanks anyway
I think the "prevention" needs to happen before handing DATA_GPS to the Spatial functions. However, this might work afterwards:
Build a MultiLineString, then check with IsClosed(). If necessary, add the original point at the end.
So I am new at ST_ functions in MySql and I think that I am missing something. I am trying to save a POLYGON in MySql, the problem is that when using the function ST_GEOMFROMTEXT and giving the coordinates of the POLYGON taken from Google Maps Javascript API it returns the error: Invalid GIS data provided to function st_geometryfromtext.
I've read a lot in Internet but everywhere it mostly says that it's a version problem, the thing here is the I have the most recent one right now (5.7.19)
These are the following queries I've tried
# WORKS
SELECT ST_GEOMFROMTEXT('POLYGON((13.517837674890684 76.453857421875,13.838079936422464 77.750244140625,14.517837674890684 79.453857421875,13.517837674890684 76.453857421875,13.517837674890684 76.453857421875))');
# ALL BELLOW RETURN ERROR
SELECT ST_GEOMFROMTEXT('POLYGON((19.4254572621497 -99.17182445526123, 19.42574056861496 -99.16570901870728, 19.421551629818985 -99.16558027267456, 19.421288552764135 -99.17210340499878))');
SELECT ST_GEOMFROMTEXT('POLYGON((-99.17182445526123 19.4254572621497, -99.16570901870728 19.42574056861496, -99.16558027267456 19.421551629818985, -99.17210340499878 19.421288552764135 ))');
SELECT ST_GEOMFROMTEXT('POLYGON((19.4249108840002 -99.17023658752441, 19.424951356518726 -99.16802644729614, 19.423393157277722 -99.16796207427979, 19.423393157277722 -99.17019367218018))')
Does anyone knows why these queries above are failing? Thank you a lot everyone
Please try these queries -
SELECT ST_GEOMFROMTEXT('POLYGON((19.4254572621497 -99.17182445526123, 19.42574056861496 -99.16570901870728, 19.421551629818985 -99.16558027267456, 19.421288552764135 -99.17210340499878, 19.4254572621497 -99.17182445526123))');
SELECT ST_GEOMFROMTEXT('POLYGON((-99.17182445526123 19.4254572621497, -99.16570901870728 19.42574056861496, -99.16558027267456 19.421551629818985, -99.17210340499878 19.421288552764135, -99.17182445526123 19.4254572621497 ))');
SELECT ST_GEOMFROMTEXT('POLYGON((19.4249108840002 -99.17023658752441, 19.424951356518726 -99.16802644729614, 19.423393157277722 -99.16796207427979, 19.423393157277722 -99.17019367218018, 19.4249108840002 -99.17023658752441))')
Basically, the polygon needs to be "closed"
I've been working with this bit of code for some time now, and now, after some tinkering, I thought I finally got it to work, then it gives me this error:
Error Number: 1096
No tables used
SELECT *
and this is the code
SELECT start.*, posts.did, COUNT(posts.pid)
FROM akia_starting_posts AS start
JOIN posts
ON posts.did = start.did
JOIN akia_users AS users
ON users.username = start.username
I'm pretty sure at the * my start is being used, so what is it talking about? It couldn't be any other code in the file, since when I take out this bit of code, it starts working.
Try to add backticks on sql string that has the word start on it. To begin try to use the one table in question first like.
SELECT 'start.*' FROM akia_starting_posts as 'start'
and if it works then you may incorporate it in fullscale join like the one you posted
with bacticks used.