Home » Server Options » Spatial » How to determine a point is inside a polygon area? (Oracle 10g , CentOS)
How to determine a point is inside a polygon area? [message #516722] Wed, 20 July 2011 04:45 Go to next message
ntt85
Messages: 34
Registered: July 2011
Location: vietnam
Member

Hi all,

I want to check a point is inside or outside a polygon area in Oracle Spatial.
Anyone can tell me how to do it?Thank you a lots.
Re: How to determine a point is inside a polygon area? [message #516736 is a reply to message #516722] Wed, 20 July 2011 07:02 Go to previous messageGo to next message
_jum
Messages: 577
Registered: February 2008
Senior Member
You could use fe. SDO_RELATE or SDO_CONTAINS.
Is the POINT (6,6,0) in the POLYGON (1,1, 10,1, 10,10, 1,10, 1,1)? :

SELECT sdo_geom.relate 
  (MDSYS.SDO_GEOMETRY(2003, NULL, NULL, MDSYS.sdo_elem_info_array(1, 1003, 1),
     MDSYS.sdo_ordinate_array(1,1, 10,1, 10,10, 1,10, 1,1)),
   'DETERMINE',
   MDSYS.SDO_GEOMETRY(2001, NULL, 
     SDO_POINT_TYPE(6,6,0), NULL,NULL),0.1) relatio
  FROM dual;

RELATIO
------------
CONTAINS     

Re: How to determine a point is inside a polygon area? [message #516822 is a reply to message #516736] Thu, 21 July 2011 02:04 Go to previous messageGo to next message
ntt85
Messages: 34
Registered: July 2011
Location: vietnam
Member

Thanks, but my polygon like :
mdsys.sdo_geometry(3,null,mdsys.sdo_point_type(null,null,null),{1, 3, 1},{105.092614, 21.718754, 105.092822, 21.7187, 105.093139, 21.718823})

May I have another options?
Re: How to determine a point is inside a polygon area? [message #516839 is a reply to message #516822] Thu, 21 July 2011 02:55 Go to previous messageGo to next message
_jum
Messages: 577
Registered: February 2008
Senior Member
Don't understand your reply, what is the problem ? Btw. your geometry is not valid!
Quote:

mdsys.sdo_geometry(3,null,mdsys.sdo_point_type(null,null,null),{1, 3, 1},{105.092614, 21.718754, 105.092822, 21.7187, 105.093139, 21.718823})
Re: How to determine a point is inside a polygon area? [message #516850 is a reply to message #516839] Thu, 21 July 2011 03:22 Go to previous messageGo to next message
ntt85
Messages: 34
Registered: July 2011
Location: vietnam
Member

Hi _jum,
That's geometry I converted from shape file, using shp2sdo.
I found data in in Pro Oracle Spatial book of Appress:
mdsys.sdo_geometry(2007,8307,mdsys.sdo_point_type(null,null,null),{1, 1003, 1, 51, 1003, 1},{-61.738891602, 17.540554047, -61.732780457, 17.541110992, -61.731117249, 17.547222137, -61.729171753, 17.608608246, -61.731674194, 17.624996185, -61.738059998, 17.644721985, -61.740280151, 17.649166107, -61.743339539, 17.653053284, -61.783615112, 17.697219849, -61.787223816, 17.700553894, -61.839172363, 17.724720001, -61.845558167, 17.724998474, -61.850280762, 17.722774506, -61.873062134, 17.703887939, -61.875282288, 17.698608398, -61.873893738, 17.68888855, -61.856674194, 17.592498779, -61.853057861, 17.583053589, -61.847503662, 17.58082962, -61.842781067, 17.582775116, -61.839447021, 17.586666107, -61.834724426, 17.588607788, -61.815559387, 17.583885193, -61.751945496, 17.549442291, -61.738891602, 17.540554047, -61.738059998, 16.989719391, -61.686668396, 17.024440765, -61.682502747, 17.027496338, -61.667503357, 17.040554047, -61.666389465, 17.045829773, -61.668891907, 17.084999084, -61.670280457, 17.090274811, -61.674171448, 17.093608856, -61.744171143, 17.137218475, -61.784172058, 17.158332825, -61.794448853, 17.163330078, -61.826393127, 17.167221069, -61.832778931, 17.163887024, -61.884170532, 17.109722137, -61.88722229, 17.1052742, -61.891113281, 17.094165802, -61.88722229, 17.033054352, -61.88583374, 17.028053284, -61.883613586, 17.023609161, -61.880561829, 17.019721985, -61.876113892, 17.016941071, -61.829170227, 16.996944427, -61.738059998, 16.989719391})


I think my geometry is a bit like this.

[Updated on: Thu, 21 July 2011 03:24]

Report message to a moderator

Re: How to determine a point is inside a polygon area? [message #516861 is a reply to message #516850] Thu, 21 July 2011 03:49 Go to previous messageGo to next message
_jum
Messages: 577
Registered: February 2008
Senior Member
The valid SDO_GEOMETRY (2007=2D-MULTIPOLYGON) could be:
SELECT 
  SDO_GEOMETRY(2007,8307,
    SDO_POINT_TYPE(null,null,null),
    SDO_ELEM_INFO_ARRAY(1, 1003, 1, 51, 1003, 1),
    SDO_ORDINATE_ARRAY(-61.738891602, 17.540554047, -61.732780457, 17.541110992, -61.731117249, 17.547222137, -61.729171753, 17.608608246, -61.731674194, 17.624996185, -61.738059998, 17.644721985, -61.740280151, 17.649166107, -61.743339539, 17.653053284, -61.783615112, 17.697219849, -61.787223816, 17.700553894, -61.839172363, 17.724720001, -61.845558167, 17.724998474, -61.850280762, 17.722774506, -61.873062134, 17.703887939, -61.875282288, 17.698608398, -61.873893738, 17.68888855, -61.856674194, 17.592498779, -61.853057861, 17.583053589, -61.847503662, 17.58082962, -61.842781067, 17.582775116, -61.839447021, 17.586666107, -61.834724426, 17.588607788, -61.815559387, 17.583885193, -61.751945496, 17.549442291, -61.738891602, 17.540554047, -61.738059998, 16.989719391, -61.686668396, 17.024440765, -61.682502747, 17.027496338, -61.667503357, 17.040554047, -61.666389465, 17.045829773, -61.668891907, 17.084999084, -61.670280457, 17.090274811, -61.674171448, 17.093608856, -61.744171143, 17.137218475, -61.784172058, 17.158332825, -61.794448853, 17.163330078, -61.826393127, 17.167221069, -61.832778931, 17.163887024, -61.884170532, 17.109722137, -61.88722229, 17.1052742, -61.891113281, 17.094165802, -61.88722229, 17.033054352, -61.88583374, 17.028053284, -61.883613586, 17.023609161, -61.880561829, 17.019721985, -61.876113892, 17.016941071, -61.829170227, 16.996944427, -61.738059998, 16.989719391)
  );
FROM dual;

[Updated on: Thu, 21 July 2011 03:51]

Report message to a moderator

Re: How to determine a point is inside a polygon area? [message #516866 is a reply to message #516861] Thu, 21 July 2011 04:11 Go to previous messageGo to next message
ntt85
Messages: 34
Registered: July 2011
Location: vietnam
Member

Thanks _jump,

Could you tell me how to convert that data to valid geometry format?
Re: How to determine a point is inside a polygon area? [message #516868 is a reply to message #516866] Thu, 21 July 2011 04:26 Go to previous messageGo to next message
_jum
Messages: 577
Registered: February 2008
Senior Member
Add SDO_ELEM_INFO_ARRAY, SDO_ORDINATE_ARRAY and remove the curly brackets '{' and '}'.
May be the SDO_GEOMETRY is correct, but only the client shows them this way as TOAD data browser does...

[Updated on: Thu, 21 July 2011 04:46]

Report message to a moderator

Re: How to determine a point is inside a polygon area? [message #516870 is a reply to message #516868] Thu, 21 July 2011 04:46 Go to previous messageGo to next message
ntt85
Messages: 34
Registered: July 2011
Location: vietnam
Member

You see, SDO_GEOMETRY is correct. But I can't execute sdo_geom.relate.I also can't replace that data Sad .

And I have another problem: my geometry is too large, so sdo_geom.relate won't execute success. I haven't found the solution yet.

[Updated on: Thu, 21 July 2011 05:03]

Report message to a moderator

Re: How to determine a point is inside a polygon area? [message #516873 is a reply to message #516870] Thu, 21 July 2011 05:15 Go to previous messageGo to next message
_jum
Messages: 577
Registered: February 2008
Senior Member
sdo_geom.relate works fine for me with your corrected geometry:
SELECT
  sdo_geom.relate( 
    SDO_GEOMETRY(2007,8307,
      SDO_POINT_TYPE(null,null,null),
      SDO_ELEM_INFO_ARRAY(1, 1003, 1, 51, 1003, 1),
      SDO_ORDINATE_ARRAY(-61.738891602, 17.540554047, -61.732780457, 17.541110992, -61.731117249, 17.547222137, -61.729171753, 17.608608246, -61.731674194, 17.624996185, -61.738059998, 17.644721985, -61.740280151, 17.649166107, -61.743339539, 17.653053284, -61.783615112, 17.697219849, -61.787223816, 17.700553894, -61.839172363, 17.724720001, -61.845558167, 17.724998474, -61.850280762, 17.722774506, -61.873062134, 17.703887939, -61.875282288, 17.698608398, -61.873893738, 17.68888855, -61.856674194, 17.592498779, -61.853057861, 17.583053589, -61.847503662, 17.58082962, -61.842781067, 17.582775116, -61.839447021, 17.586666107, -61.834724426, 17.588607788, -61.815559387, 17.583885193, -61.751945496, 17.549442291, -61.738891602, 17.540554047, -61.738059998, 16.989719391, -61.686668396, 17.024440765, -61.682502747, 17.027496338, -61.667503357, 17.040554047, -61.666389465, 17.045829773, -61.668891907, 17.084999084, -61.670280457, 17.090274811, -61.674171448, 17.093608856, -61.744171143, 17.137218475, -61.784172058, 17.158332825, -61.794448853, 17.163330078, -61.826393127, 17.167221069, -61.832778931, 17.163887024, -61.884170532, 17.109722137, -61.88722229, 17.1052742, -61.891113281, 17.094165802, -61.88722229, 17.033054352, -61.88583374, 17.028053284, -61.883613586, 17.023609161, -61.880561829, 17.019721985, -61.876113892, 17.016941071, -61.829170227, 16.996944427, -61.738059998, 16.989719391)),
    'DETERMINE',
    MDSYS.SDO_GEOMETRY(2001, 8307,SDO_POINT_TYPE(-61.73,17,0), NULL,NULL)
  ,0.1)
FROM dual;

SDO_GEOM.RELATE(SDO_GEOMETRY(2007,8307,SDO_POINT_TYPE(NULL,NULL,NULL),SDO_ELEM_I
--------------------------------------------------------------------------------
CONTAINS                                                                        
1 row selected.


Re: How to determine a point is inside a polygon area? [message #516879 is a reply to message #516873] Thu, 21 July 2011 05:27 Go to previous messageGo to next message
ntt85
Messages: 34
Registered: July 2011
Location: vietnam
Member

Oh no, that's data smaller than my real data. I attached my real data below. Sad
  • Attachment: geo.txt
    (Size: 63.36KB, Downloaded 2517 times)
Re: How to determine a point is inside a polygon area? [message #516896 is a reply to message #516879] Thu, 21 July 2011 06:29 Go to previous messageGo to next message
_jum
Messages: 577
Registered: February 2008
Senior Member
Seems that you can max. 499 coords put in an SDO_ORDINATE_ARRAY this way.
Re: How to determine a point is inside a polygon area? [message #517030 is a reply to message #516896] Thu, 21 July 2011 20:49 Go to previous messageGo to next message
ntt85
Messages: 34
Registered: July 2011
Location: vietnam
Member

I need to check a point is in the city or not.
Ex: I have a point: mdsys.sdo_geometry(2001,8307,mdsys.sdo_point_type(105.424,21.315,null),{},{})
And I have to check that point is in what city?
The data cities is in the shapefiles, I used shp2sdo convert to Oracle Spatial, its very large.
I haven't had a solution yet. Can u have some advices?

My shape file data at : http://www.mediafire.com/?pk0wf8inrsipn1m.
Re: How to determine a point is inside a polygon area? [message #517033 is a reply to message #517030] Thu, 21 July 2011 22:12 Go to previous message
ntt85
Messages: 34
Registered: July 2011
Location: vietnam
Member

Hey _jump,
I've had a new solution.
I will ask you later if I have another questions.
Thank you very much.
Previous Topic: Problem when Loading ESRI Shapefiles into Spatial
Next Topic: Results from outside an SDO_FILTER
Goto Forum:
  


Current Time: Fri Mar 29 00:36:03 CDT 2024