예제 #1
0
    void object::test<1>()
    {
	    GEOSGeometry* geom1 = GEOSGeomFromWKT("POLYGON EMPTY");

		ensure ( 0 != GEOSisEmpty(geom1) );

		GEOSGeometry* geom2 = GEOSSimplify(geom1, 43.2);

		ensure ( 0 != GEOSisEmpty(geom2) );
    }
예제 #2
0
void object::test<1>()
{
    geom1_ = GEOSGeomFromWKT("POLYGON EMPTY");

    ensure ( 0 != GEOSisEmpty(geom1_) );

    geom2_ = GEOSSimplify(geom1_, 43.2);

    ensure ( 0 != GEOSisEmpty(geom2_) );
}
예제 #3
0
long long msudf_isEmpty(UDF_INIT *initid,UDF_ARGS *args,char *is_null, char *error)
{
	GEOSGeom geom;
	long long result;

	DEBUG("msudf_isEmpty");
	
	geom = msudf_getGeometry((unsigned char *)args->args[0],args->lengths[0]);
	
	if (geom == NULL) {
		strcpy(error,"Invalid geometry.");
		*is_null = 1;
		return 0;
	}

	result = GEOSisEmpty(geom);
	if (geom != NULL) GEOSGeom_destroy(geom);

	if (result >1) {
		*is_null = 1;
		return 0;
	} else {
		return result;
	}
}
예제 #4
0
파일: mapgeos.c 프로젝트: codeforeurope/gim
shapeObj *msGEOSGeometry2Shape(GEOSGeom g)
{
  int type;

  if(!g) 
    return NULL; /* a NULL geometry generates a NULL shape */

  type = GEOSGeomTypeId(g);
  switch(type) {
  case GEOS_POINT:
    return msGEOSGeometry2Shape_point(g);
    break;
  case GEOS_MULTIPOINT:
    return msGEOSGeometry2Shape_multipoint(g);
    break;
  case GEOS_LINESTRING:
    return msGEOSGeometry2Shape_line(g);
    break;
  case GEOS_MULTILINESTRING:
    return msGEOSGeometry2Shape_multiline(g);
    break;
  case GEOS_POLYGON:
    return msGEOSGeometry2Shape_polygon(g);
    break;
  case GEOS_MULTIPOLYGON:
    return msGEOSGeometry2Shape_multipolygon(g);
    break;
  default:
    if (!GEOSisEmpty(g))
        msSetError(MS_GEOSERR, "Unsupported GEOS geometry type (%d).", "msGEOSGeometry2Shape()", type);
    return NULL;
  }
}
예제 #5
0
    void object::test<1>()
    {
        geom_ = GEOSGeomFromWKT("POLYGON EMPTY");

        ensure ( 0 != GEOSisEmpty(geom_) );

        int in = 1;
        GEOSGeom_setUserData(geom_, &in);

        int* out = (int *)GEOSGeom_getUserData(geom_);

        ensure_equals(*out, 1);
    }
    void object::test<1>()
    {
        input_ = GEOSGeomFromWKT("MULTIPOINT (130 240, 130 240, 130 240, 570 240, 570 240, 570 240, 650 240)");
        ensure( 0 != input_ );

        expected_ = GEOSGeomFromWKT("LINESTRING (130 240, 650 240, 130 240)");   
        ensure( 0 != expected_ );

        GEOSGeometry* output = GEOSConvexHull(input_);
        ensure( 0 != output );
        ensure( 0 == GEOSisEmpty(output) );
        // TODO
        //ensure( 0 != GEOSEquals(output, expected_));
    }
예제 #7
0
void object::test<1>
()
{
    input_ = GEOSGeomFromWKT("POLYGON ((1 6, 6 11, 11 6, 6 1, 1 6))");
    ensure(nullptr != input_);

    GEOSGeometry* output = GEOSMinimumRotatedRectangle(input_);
    ensure(nullptr != output);
    ensure(0 == GEOSisEmpty(output));

    wkt_ = GEOSWKTWriter_write(wktw_, output);
    ensure_equals(std::string(wkt_), std::string("POLYGON ((6 1, 11 6, 6 11, 1 6, 6 1))"));

    GEOSGeom_destroy(output);
}
    static size_t
asgeojson_point_buf(GEOSGeom point, char *srs, char *output, bbox3D *bbox, int precision)
{
    char *ptr = output;

    ptr += sprintf(ptr, "{\"type\":\"Point\",");
    if (srs) ptr += asgeojson_srs_buf(ptr, srs);
    if (bbox) ptr += asgeojson_bbox_buf(ptr, bbox, GEOS_getWKBOutputDims(point) == 3, precision);

    ptr += sprintf(ptr, "\"coordinates\":");
    if ( GEOSisEmpty(point) == 1 )
        ptr += sprintf(ptr, "[]");
    ptr += points_to_geojson(point, ptr, precision);
    ptr += sprintf(ptr, "}");

    return (ptr-output);
}
    static size_t
asgeojson_point_size(GEOSGeom point, char *srs, bbox3D *bbox, int precision)
{
    int size;

    size = points_geojson_size(point, precision);
    size += sizeof("{'type':'Point',");
    size += sizeof("'coordinates':}");

    if ( GEOSisEmpty(point) == 1 )
        size += 2; /* [] */

    if (srs) size += asgeojson_srs_size(srs);
    if (bbox) size += asgeojson_bbox_size(GEOS_getWKBOutputDims(point) == 3, precision);

    return size;
}
예제 #10
0
    void object::test<2>()
    {
        geom_ = GEOSGeomFromWKT("POLYGON EMPTY");

        ensure ( 0 != GEOSisEmpty(geom_) );

        UserData in;
        in.a = 1;
        in.b = 2;

        GEOSGeom_setUserData(geom_, &in);

        struct UserData* out = (struct UserData* )GEOSGeom_getUserData(geom_);

        ensure_equals(in.a, out->a);
        ensure_equals(in.b, out->b);
        ensure_equals(&in, out);
    }
예제 #11
0
void geo_empty(sqlite3_context *context,int argc,sqlite3_value **argv)
{
	if(argc == 1 && sqlite3_value_type(argv[0]) == SQLITE_BLOB)
	{ 
		GEOSGeometry* geometry;
		const void* data = sqlite3_value_blob(argv[0]);
		size_t data_size = sqlite3_value_bytes(argv[0]);

		_init_geos();
		geometry = _geo_from_wkb((const unsigned char*)data,data_size);
		if(geometry != 0)
		{
			char empty = (GEOSisEmpty(geometry) == 1) ? 1 : 0;
			sqlite3_result_int(context,empty);
		}
		GEOSGeom_destroy(geometry);
		finishGEOS();
	}
}
예제 #12
0
파일: erlgeom.c 프로젝트: gleber/erlgeom
static ERL_NIF_TERM
geom_to_eterm(ErlNifEnv *env, const GEOSGeometry *geom)
{
    ERL_NIF_TERM coords;
    int type = GEOSGeomTypeId(geom);

    switch(type) {
    case GEOS_POINT:
        if (GEOSisEmpty(geom)) {
            coords = enif_make_list(env, 0);
        }
        else {
            coords = geom_to_eterm_point_coords(env, geom);
        }
        return enif_make_tuple2(env, enif_make_atom(env, "Point"), coords);
    case GEOS_LINESTRING:
        if (GEOSisEmpty(geom)) {
            coords = enif_make_list(env, 0);
        }
        else {
            coords = geom_to_eterm_linestring_coords(env, geom);
        }
        return enif_make_tuple2(env, enif_make_atom(env, "LineString"),
            coords);
    case GEOS_POLYGON:
        if (GEOSisEmpty(geom)) {
            coords = enif_make_list(env, 0);
        }
        else {
            coords = geom_to_eterm_polygon_coords(env, geom);
        }
        return enif_make_tuple2(env, enif_make_atom(env, "Polygon"), coords);
    case GEOS_MULTIPOINT:
        if (GEOSisEmpty(geom)) {
            coords = enif_make_list(env, 0);
        }
        else {
            coords = geom_to_eterm_multi_coords(env, geom,
                geom_to_eterm_point_coords);
        }
        return enif_make_tuple2(env, enif_make_atom(env, "MultiPoint"),
            coords);
    case GEOS_MULTILINESTRING:
        if (GEOSisEmpty(geom)) {
            coords = enif_make_list(env, 0);
        }
        else {
            coords = geom_to_eterm_multi_coords(env, geom,
                geom_to_eterm_linestring_coords);
        }
        return enif_make_tuple2(env, enif_make_atom(env, "MultiLineString"),
            coords);
    case GEOS_MULTIPOLYGON:
        if (GEOSisEmpty(geom)) {
            coords = enif_make_list(env, 0);
        }
        else {
            coords = geom_to_eterm_multi_coords(env, geom,
                geom_to_eterm_polygon_coords);
        }
        return enif_make_tuple2(env, enif_make_atom(env, "MultiPolygon"),
            coords);
    case GEOS_GEOMETRYCOLLECTION:
        if (GEOSisEmpty(geom)) {
            coords = enif_make_list(env, 0);
        }
        else {
            coords = geom_to_eterm_multi_coords(env, geom, geom_to_eterm);
        }
        return enif_make_tuple2(env, enif_make_atom(env, "GeometryCollection"),
            coords);
    }
    return -1;
}
예제 #13
0
/* Return an LWGEOM from a Geometry */
LWGEOM *
GEOS2LWGEOM(const GEOSGeometry *geom, char want3d)
{
	int type = GEOSGeomTypeId(geom) ;
	int hasZ;
	int SRID = GEOSGetSRID(geom);

	/* GEOS's 0 is equivalent to our unknown as for SRID values */
	if ( SRID == 0 ) SRID = SRID_UNKNOWN;

	if ( want3d )
	{
		hasZ = GEOSHasZ(geom);
		if ( ! hasZ )
		{
			LWDEBUG(3, "Geometry has no Z, won't provide one");

			want3d = 0;
		}
	}

/*
	if ( GEOSisEmpty(geom) )
	{
		return (LWGEOM*)lwcollection_construct_empty(COLLECTIONTYPE, SRID, want3d, 0);
	}
*/

	switch (type)
	{
		const GEOSCoordSequence *cs;
		POINTARRAY *pa, **ppaa;
		const GEOSGeometry *g;
		LWGEOM **geoms;
		uint32_t i, ngeoms;

	case GEOS_POINT:
		LWDEBUG(4, "lwgeom_from_geometry: it's a Point");
		cs = GEOSGeom_getCoordSeq(geom);
		if ( GEOSisEmpty(geom) )
		  return (LWGEOM*)lwpoint_construct_empty(SRID, want3d, 0);
		pa = ptarray_from_GEOSCoordSeq(cs, want3d);
		return (LWGEOM *)lwpoint_construct(SRID, NULL, pa);

	case GEOS_LINESTRING:
	case GEOS_LINEARRING:
		LWDEBUG(4, "lwgeom_from_geometry: it's a LineString or LinearRing");
		if ( GEOSisEmpty(geom) )
		  return (LWGEOM*)lwline_construct_empty(SRID, want3d, 0);

		cs = GEOSGeom_getCoordSeq(geom);
		pa = ptarray_from_GEOSCoordSeq(cs, want3d);
		return (LWGEOM *)lwline_construct(SRID, NULL, pa);

	case GEOS_POLYGON:
		LWDEBUG(4, "lwgeom_from_geometry: it's a Polygon");
		if ( GEOSisEmpty(geom) )
		  return (LWGEOM*)lwpoly_construct_empty(SRID, want3d, 0);
		ngeoms = GEOSGetNumInteriorRings(geom);
		ppaa = lwalloc(sizeof(POINTARRAY *)*(ngeoms+1));
		g = GEOSGetExteriorRing(geom);
		cs = GEOSGeom_getCoordSeq(g);
		ppaa[0] = ptarray_from_GEOSCoordSeq(cs, want3d);
		for (i=0; i<ngeoms; i++)
		{
			g = GEOSGetInteriorRingN(geom, i);
			cs = GEOSGeom_getCoordSeq(g);
			ppaa[i+1] = ptarray_from_GEOSCoordSeq(cs,
			                                      want3d);
		}
		return (LWGEOM *)lwpoly_construct(SRID, NULL,
		                                  ngeoms+1, ppaa);

	case GEOS_MULTIPOINT:
	case GEOS_MULTILINESTRING:
	case GEOS_MULTIPOLYGON:
	case GEOS_GEOMETRYCOLLECTION:
		LWDEBUG(4, "lwgeom_from_geometry: it's a Collection or Multi");

		ngeoms = GEOSGetNumGeometries(geom);
		geoms = NULL;
		if ( ngeoms )
		{
			geoms = lwalloc(sizeof(LWGEOM *)*ngeoms);
			for (i=0; i<ngeoms; i++)
			{
				g = GEOSGetGeometryN(geom, i);
				geoms[i] = GEOS2LWGEOM(g, want3d);
			}
		}
		return (LWGEOM *)lwcollection_construct(type,
		                                        SRID, NULL, ngeoms, geoms);

	default:
		lwerror("GEOS2LWGEOM: unknown geometry type: %d", type);
		return NULL;

	}

}
void VertexSnapper::editGeometry( MyGEOSGeom *geom, GEOSCoordSequence *coord )
{
    // edit geometry according to coord -> GeometryEditor and GeometryEditorOperation/interface classes ??????

    qDebug("VertexSnapper::editGeometry: ENTERING EDIT GEOMETRY");

    // new geometry
    GEOSGeometry *newGeom = NULL;
    GEOSGeometry *ring = NULL;

    // change geometry according to its type  // NOTE: improve this according to http://trac.osgeo.org/geos/browser/trunk/tests/geostest/geostest.c - fineGrainedReconstructionTest
    int type = GEOSGeomTypeId( geom->getGEOSGeom() );
    switch ( type )
    {
        case GEOS_POINT:
            newGeom = GEOSGeom_createPoint( coord );
            break;
        case GEOS_LINESTRING:
            newGeom = GEOSGeom_createLineString( coord );
            break;
        case GEOS_LINEARRING:
            newGeom = GEOSGeom_createLinearRing( coord );
            break;
        case GEOS_POLYGON:
            ring = GEOSGeom_createLinearRing( coord ); // NOTE: Fails if polygon has holes
            newGeom = GEOSGeom_createPolygon( ring, NULL, 0 );
            break;
        case GEOS_MULTIPOINT:
            newGeom = GEOSGeom_createEmptyCollection(4);
            qDebug("VertexSnapper::editGeometry: Multi geometry is not supported yet.");
            break;
        case GEOS_MULTILINESTRING:
            newGeom = GEOSGeom_createEmptyCollection(5);
            qDebug("VertexSnapper::editGeometry: Multi geometry is not supported yet.");
            break;
        case GEOS_MULTIPOLYGON:
            newGeom = GEOSGeom_createEmptyCollection(6);
            qDebug("VertexSnapper::editGeometry: Multi geometry is not supported yet.");
            break;
        case GEOS_GEOMETRYCOLLECTION:
            newGeom = GEOSGeom_createEmptyCollection(7);
            qDebug("VertexSnapper::editGeometry: Multi geometry is not supported yet.");
            break;
        default:
            qDebug("VertexSnapper::editGeometry: Unknown geometry type.");
    }


    // return edited geometry
    geom->setGEOSGeom( newGeom );


    if( GEOSisEmpty( geom->getGEOSGeom() ) )
        qDebug("VertexSnapper::editGeometry: Geom is empty.");

    if( GEOSisValid( geom->getGEOSGeom() ) )
        qDebug("VertexSnapper::editGeometry: Geom is valid.");


    //GEOSGeom_destroy(newGeom);


} // void VertexSnapper::editGeometry( MyGEOSGeom &geom, CoordinateSequence &coord )