sql - MySQL Point in Polygon Queries and DB Setup -


i trying set table consists of regions polygon. want able query table find whether given point lies in of stored regions or not.

i read mysql spatial extensions provide 2 types of functions operate geometries:

  • st_* operating on object shapes
  • mbr* operating on minimum bounding rectangles

i tried following worked in this post. here's how set table:

create table `region` ( `id` int(11) unsigned not null auto_increment, `name` varchar(50) not null, `rpolygon` polygon not null, primary key (`id`) ) engine=innodb default charset=utf8; 

i inserted few records in table after getting polygon definitions qgis. learned inserting spatial records table here. here's how inserted record in table

set @g= st_geomfromtext('polygon ((-117.84293016891291472 33.64825334189644224, -117.8428418279120109 33.64599663087331294, -117.84048874488789238 33.64467151585973426, -117.84002294688312418 33.64517746886491523, -117.83983020288114574 33.64549067786812486, -117.83981414088098916 33.64605284787388939, -117.83983823388122403 33.64646242887808825, -117.84012734988419879 33.64708081588442212, -117.84053693088839054 33.64743417988804453, -117.84130790689629009 33.6479401328932326, -117.84199054190328582 33.64815696989545302, -117.84243224690781915 33.64822121789610776, -117.84293016891291472 33.64825334189644224))'); insert region  values(1, 'north-east', @g); 

just sanity check, tried running point in polygon query using various methods - mbrcontains, st_contains etc, of result in no results or null. below sample query tried:

select * region st_contains(rpolygon, st_geomfromtext('point(33.646201 -117.841949)')); 

i not sure going wrong. storing values incorrectly, set geo table in different way?, or querying incorrectly. couldn't find tutorials online or examples follow such setup. pointers helpful!

damn! feel pretty stupid! order of coordinates wrong in query define point.

anyway. hope serves short tutorial wanting started point-in-polygon queries mysql


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -