I've seen that with st_intersects you can call...
ST_INTERSECTS('geometry', circle(latlng(lat,lng),1))
How do you write it if you want to have a polygon instead?
ST_INTERSECTS('geometry', polygon(
outerBoundaryIs(
latlng(lat,lng),latlng(lat,lng)),(..next shape)
)))
or can we actually use kml like this in some way?
ST_INTERSECTS('geometry', '<MultiGeometry><Polygon>
<tessellate>1</tessellate><extrude>0</extrude>
<altitudeMode>clampToGround</altitudeMode>
<outerBoundaryIs><LinearRing>
<coordinates>lats,lngs</coordinates>
</LinearRing></outerBoundaryIs></Polygon></MultiGeometry>')
Thanks!
Quince
ANSWER(wouldn't let me post it yet):
I figured this par out.
SELECT 'name' FROM 1vVUoTyGcnlbxmd66lZeHj81-tbgpIyKpVmXaZxYH
WHERE ST_INTERSECTS('geometry',
POLYGON(
LATLNG(40.249528, -120.8435),
LATLNG(40.258326, -121.061249),
LATLNG(40.301765, -121.007911),
LATLNG(40.249528, -120.8435)
))
You can execute the query at the link below.
https://console.developers.google.com/project/280742519599/apiui/api/fusiontables/method/fusiontables.query.sql
FusionTables doesn't support the intersection of 2 polygons. There is a feature request that has been marked "WontFix"
Related
I'm trying to save some KML files to PostgreSQL.
I'm using postgis and this is a sample of what I've done so far.
INSERT INTO police_crime_boundaries (name, polygon) VALUES (
'A',
ST_GeomFromKML('<LinearRing>
<coordinates>-2.69927798816,52.9954289967,0 -2.70075298816,52.9932649967,0
</coordinates>
</LinearRing>')
);
Anyone have any idea of what am I doing wrong?
Getting the data from here: https://data.police.uk/data/boundaries/
LinearRing can not be stored to/retrieved from a Geometry column (see the document)
So you should either use <Polygon> tag instead of <LinearRing> or wrap it with OuterBoundary and Polygon tags like below :
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>0,0 0,1 1,1 1,0 0,0</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
I'm trying to create a middle line through a polygon path but having problems, now i'm totally lost how to do it. Can anyone help to achieve this goal ?
ST_ApproximateMedialAxis might be what you're looking for.
This PostGIS function can be installed with the extension postgis_sfcgal:
CREATE EXTENSION postgis_sfcgal
Data Sample:
CREATE TABLE t (geom GEOMETRY);
INSERT INTO t VALUES ('POLYGON((-4.689807593822478 54.20411976258862,-4.68751162290573 54.20415427666532,-4.686465561389922 54.20414172609529,-4.685768187046051 54.20414800138079,-4.685280025005341 54.20414486373812,-4.685070812702178 54.204126037877415,-4.685092270374298 54.2040538719985,-4.685854017734527 54.204078973188075,-4.687039554119109 54.20407583554021,-4.688123166561126 54.204082110835685,-4.689078032970428 54.2040601472973,-4.689936339855194 54.20403818374726,-4.689807593822478 54.20411976258862))');
Query:
SELECT ST_ASText(ST_ApproximateMedialAxis(geom)) FROM t;
--------------------------------------------------------
MULTILINESTRING((-4.68993633985519 54.2040381837473,-4.68979598869017 54.2040808603332),(-4.68812343743121 54.2041135944836,-4.68907889005644 54.2040954248621),(-4.68812343743121 54.2041135944836,-4.68751156547988 54.2041164214432),(-4.68646560965613 54.2041095395079,-4.6858535007301 54.2041131034922),(-4.68646560965613 54.2041095395079,-4.68703949691079 54.2041122226661),(-4.6858535007301 54.2041131034922,-4.68576814087419 54.2041120816007),(-4.68907889005644 54.2040954248621,-4.68979598869017 54.2040808603332),(-4.68576814087419 54.2041120816007,-4.68528206303828 54.2041025125126),(-4.68703949691079 54.2041122226661,-4.68751156547988 54.2041164214432),(-4.68512015518242 54.2040925683677,-4.68528206303828 54.2041025125126))
(1 Zeile)
Depending on your use case, another option would be ST_StraightSkeleton:
SELECT ST_ASText(ST_StraightSkeleton(geom)) FROM t;
-----------------------------------------------------
MULTILINESTRING((-4.68980759382248 54.2041197625886,-4.68979598869017 54.2040808603332),(-4.68993633985519 54.2040381837473,-4.68979598869017 54.2040808603332),(-4.68907803297043 54.2040601472973,-4.68907889005644 54.2040954248621),(-4.68812316656113 54.2040821108357,-4.68812343743121 54.2041135944836),(-4.68703955411911 54.2040758355402,-4.68703949691079 54.2041122226661),(-4.68585401773453 54.2040789731881,-4.6858535007301 54.2041131034922),(-4.6850922703743 54.2040538719985,-4.68512015518242 54.2040925683677),(-4.68507081270218 54.2041260378774,-4.68512015518242 54.2040925683677),(-4.68528002500534 54.2041448637381,-4.68528206303828 54.2041025125126),(-4.68576818704605 54.2041480013808,-4.68576814087419 54.2041120816007),(-4.68646556138992 54.2041417260953,-4.68646560965613 54.2041095395079),(-4.68751162290573 54.2041542766653,-4.68751156547988 54.2041164214432),(-4.68812343743121 54.2041135944836,-4.68907889005644 54.2040954248621),(-4.68812343743121 54.2041135944836,-4.68751156547988 54.2041164214432),(-4.68646560965613 54.2041095395079,-4.6858535007301 54.2041131034922),(-4.68646560965613 54.2041095395079,-4.68703949691079 54.2041122226661),(-4.6858535007301 54.2041131034922,-4.68576814087419 54.2041120816007),(-4.68907889005644 54.2040954248621,-4.68979598869017 54.2040808603332),(-4.68576814087419 54.2041120816007,-4.68528206303828 54.2041025125126),(-4.68703949691079 54.2041122226661,-4.68751156547988 54.2041164214432),(-4.68512015518242 54.2040925683677,-4.68528206303828 54.2041025125126))
(1 Zeile)
I get what seems like a bug in Postgresql/Postgis. This is a completely reproducible example that demonstrates the problem:
#create a new srid for local area (formula for proj4text is taken from Quantum GIS)
INSERT INTO spatial_ref_sys (srid, auth_name, auth_srid, proj4text) VALUES (998997, 'EPSG', 998997, '+proj=tmerc +lat_0=0 +lon_0=44.55 +k=1 +x_0=2250000 +y_0=-5714743.504 +ellps=krass +towgs84=24,-123,-94,0.02,-0.25,-0.13,1.1 +units=m +no_defs ');
#create a new table for storing geometry data:
CREATE TABLE layer(
id SERIAL PRIMARY KEY,
geom geometry,
CONSTRAINT enforce_dims_geom_layer CHECK (st_ndims(geom) = 2),
CONSTRAINT enforce_srid_geom_layer CHECK (st_srid(geom) = 998997)
);
#add one polygon to the table:
INSERT INTO layer (geom) VALUES (ST_Force2D(ST_Transform(ST_GeomFromText('POLYGON((4832654.676302 7570323.2813639, 4810946.560269 7597840.6115465, 4836629.4017728 7629944.1634263, 4886772.0923279 7629944.1634263, 4902059.4979849 7591725.6492837, 4864452.4800686 7553507.1351411, 4832654.676302 7570323.2813639),(4845190.3489408 7589891.1606049, 4855585.7847875 7610376.2841853, 4876988.1527074 7604567.0700356, 4874847.9159154 7588362.4200392, 4858031.7696927 7575520.9992872, 4845190.3489408 7589891.1606049))', 3857),998997)));
#check that this polygon is valid!
SELECT ST_IsValid(ST_Force2D(ST_Transform(ST_GeomFromText('POLYGON((4832654.676302 7570323.2813639, 4810946.560269 7597840.6115465, 4836629.4017728 7629944.1634263, 4886772.0923279 7629944.1634263, 4902059.4979849 7591725.6492837, 4864452.4800686 7553507.1351411, 4832654.676302 7570323.2813639),(4845190.3489408 7589891.1606049, 4855585.7847875 7610376.2841853, 4876988.1527074 7604567.0700356, 4874847.9159154 7588362.4200392, 4858031.7696927 7575520.9992872, 4845190.3489408 7589891.1606049))', 3857),998997))) AS is_valid;
#^^^ it returns t. so, the geometry is 100% ok.
#check how it looks like in geojson format:
SELECT ST_AsGeoJSON(ST_Transform(geom, 3857))::json from layer
#^^^ Again it's ok and returns some nice geojson data
#Final step. Check ST_ApproximateMedialAxis function
SELECT ST_ApproximateMedialAxis(ST_Transform(geom, 3857)) from layer;
The final query returns an error message:
ERROR: Polygon is invalid : exterior ring and interior ring 0 have the same orientation : POLYGON((5189023446929109/1073741824 2032143182100511/268435456,5165714534831303/1073741824 31867653268373/4194304,1298322818976529/268435456 8192590163056015/1073741824,26
********** Error **********
So, all ingredients seem to be ok - formula for srid is taken from some standard widely used tool, data is inserted into the table without problems, the data is validated by ST_IsValid, geojson representation of data is also ok, but one library function still does not like something.
I have found this nice thread and came to the solution. I just have to use ST_ForceRHR Postgis function which
forces the orientation of the vertices in a polygon to follow the Right-Hand-Rule
So the right way to insert the data was:
INSERT INTO layer (geom) VALUES (ST_Force2D(ST_Transform(ST_ForceRHR(ST_GeomFromText('POLYGON((4832654.676302 7570323.2813639, 4810946.560269 7597840.6115465, 4836629.4017728 7629944.1634263, 4886772.0923279 7629944.1634263, 4902059.4979849 7591725.6492837, 4864452.4800686 7553507.1351411, 4832654.676302 7570323.2813639),(4845190.3489408 7589891.1606049, 4855585.7847875 7610376.2841853, 4876988.1527074 7604567.0700356, 4874847.9159154 7588362.4200392, 4858031.7696927 7575520.9992872, 4845190.3489408 7589891.1606049))', 3857)),998997)));
Is there a way to make a copy of an arbitrary OrientDB record without its edges? I modified an original command (from the docs) for copying records and added fetchplan to it, but it does not work (frankly speaking to me it looks like there's a problem parsing this particular command, but hopefully im wrong)
This one executes fine, but edges remain:
insert into Test from select from Test where #rid=#102:119 fetchplan in_*:-2 out_*:-2
This one gives an error:
insert into Test from (select from Test where #rid=#102:119 fetchplan in_*:-2 out_*:-2)
com.orientechnologies.orient.core.command.OCommandExecutorNotFoundException: Cannot find a command executor for the command request: sql.(SELECT FROM Test WHERE #rid = #102:119 FETCHPLAN in_*:-2 out_*:-2)
also tried smth like
insert into Test content (select #this.toJSON('fetchPlan:in_*:-2 out_*:-2') from Test where #rid=#102:119)
but that doesn't work either. Any thoughts? I'm on Orient 2.1.x
As workaround you can use this javascript function with one parameter (id)
var g=orient.getGraph();
var b=g.command("sql","select #this.toJSON('fetchPlan:in_*:-2 out_*:-2') as json from "+ id);
if(b.length>0){
var query="insert into Test content " + b[0].getProperty("json") ;
var myVertex=g.command("sql",query);
g.commit();
return myVertex;
}
Using the following command
select expand(result) from (select yourFunction(#102:119) as result)
Here's how to select all vertices (V) that have no incoming or outgoing edges:
select from (select #this, bothE().size() as n from V) where n = 0
I tried your query and I have the same problem.
I solved it in this way:
insert into Test from select <property-name> from Test where #rid=#102:119
If you want use it with fatchplan try this:
insert into Test from select <property-name> from Test where #rid=#102:119 fetchplan in_*:-2 out_*:-2
Hope it helps.
Regards,
Michela
My client website using Zendframework. Now they ask me to random the result. I using RAND() but not working. Anybody can help?
Here is the code (the RAND() at the bottom)
$oPlaceSelect = $oPlaces->select()->setIntegrityCheck(false)
->from(array('p' => 'places'),
array('id', 'place_title' => 'title', 'alias', 'categories_id',
=> '(SELECT path FROM places_images WHERE places_images.places_id = p.id group by places_id)'))
->order('RAND()');
Thanks,
To use mysql function in a Zend Select object, you need to use 'Zend_Db_Expr'
->order(new Zend_Db_Expr("RAND()"));