123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- #include <grass/gis.h>
- #include <grass/dbmi.h>
- #include <grass/vector.h>
- #include <grass/glocale.h>
- #include "proto.h"
- #ifdef HAVE_GEOS
- static int relate_geos(struct Map_info *, const GEOSGeometry *,
- int, int, const char *, int);
- int line_relate_geos(struct Map_info *AIn, const GEOSGeometry *BGeom,
- int aline, int operator, const char *relate)
- {
- return relate_geos(AIn, BGeom, aline, operator, relate, 0);
- }
- int area_relate_geos(struct Map_info *AIn, const GEOSGeometry *BGeom,
- int aarea, int operator, const char *relate)
- {
- return relate_geos(AIn, BGeom, aarea, operator, relate, 1);
- }
- int relate_geos(struct Map_info *AIn, const GEOSGeometry *BGeom,
- int afid, int operator, const char *relate, int area)
- {
- GEOSGeometry *AGeom = NULL;
- int found;
- found = 0;
- if (area)
- AGeom = Vect_read_area_geos(AIn, afid);
- else
- AGeom = Vect_read_line_geos(AIn, afid, NULL);
- if (!AGeom)
- return 0;
- /*
- if (!BGeom) {
- if (area)
- G_fatal_error(_("Unable to read area id %d from vector map <%s>"),
- bfid, Vect_get_full_name(BIn));
- else
- G_fatal_error(_("Unable to read line id %d from vector map <%s>"),
- bfid, Vect_get_full_name(BIn));
- }
- */
- switch (operator) {
- case OP_EQUALS:{
- if (GEOSEquals(AGeom, BGeom)) {
- found = 1;
- break;
- }
- break;
- }
- case OP_DISJOINT:{
- if (GEOSDisjoint(AGeom, BGeom)) {
- found = 1;
- break;
- }
- break;
- }
- case OP_INTERSECTS:{
- if (GEOSIntersects(AGeom, BGeom)) {
- found = 1;
- break;
- }
- break;
- }
- case OP_TOUCHES:{
- if (GEOSTouches(AGeom, BGeom)) {
- found = 1;
- break;
- }
- break;
- }
- case OP_CROSSES:{
- if (GEOSCrosses(AGeom, BGeom)) {
- found = 1;
- break;
- }
- break;
- }
- case OP_WITHIN:{
- if (GEOSWithin(AGeom, BGeom)) {
- found = 1;
- break;
- }
- break;
- }
- case OP_CONTAINS:{
- if (GEOSContains(AGeom, BGeom)) {
- found = 1;
- break;
- }
- break;
- }
- case OP_OVERLAPS:{
- if (GEOSOverlaps(AGeom, BGeom)) {
- found = 1;
- break;
- }
- break;
- }
- case OP_RELATE:{
- if (GEOSRelatePattern(AGeom, BGeom, relate)) {
- found = 1;
- break;
- }
- break;
- }
- default:
- break;
- }
- if (AGeom)
- GEOSGeom_destroy(AGeom);
- return found;
- }
- #endif /* HAVE_GEOS */
|