Hibernate spatial index annotation
Asked Answered
H

1

10

I am using jts geometry object to store my geometry objects as an Oracle SDO_Geometry. However when I want to use SDO_GEOM.RELATE methods they are not working properly,I realized that I need to create a spatial index but dont know how to do with hibernate. Do you know any annotation for this problem.

@Type(type="org.hibernate.spatial.GeometryType")
 private Geometry area;
Harassed answered 3/8, 2015 at 13:3 Comment(0)
K
3

Well, just create the index on the table where you store those geometries. Use SQL for that.

You need also (before you create the index) to add the proper metadata so that the index creation has the proper information it needs (coordinate system, bounds, tolerance). For example, assuming your geometries are in WGS84 coordinates:

insert into user_sdo_geom_metadata (table_name, column_name, diminfo, srid)
values (
  'US_CITIES', 
  'GEOMETRY',
  sdo_dim_array (
    sdo_dim_element('long', -180.0, 180.0, 0.5),
    sdo_dim_element('lat', -90.0, 90.0, 0.5)
  ),
  4326
);
commit;

Then create the index:

create index us_cities_sx on us_cities (geometry)
  indextype is mdsys.spatial_index;
Kamin answered 4/8, 2015 at 9:23 Comment(2)
Well, I created index as you told still have some problems when I try to validate my geometry with SDO_GEOM.VALIDATE_GEOMETRY I got 13349 error.Harassed
First of all use SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT(). Then error 13349 means that your shape (a polygon) is "twisted",i.e "self-crossing". You will not be able to use for any actual processing (searches, measurements, buffering, unioning, etc.). I have no idea how you construct your objects, or where you get them from, but that one is wrong and you must correct it.Kamin

© 2022 - 2024 — McMap. All rights reserved.