added ability to delete geometries.

git-svn-id: http://svn.osgeo.org/postgis/trunk@303 b70326c6-7e19-0410-871a-916f4a2858ee
This commit is contained in:
David Blasby 2003-09-16 20:27:12 +00:00
parent be9b09ea85
commit 0dbf38b56a
6 changed files with 122 additions and 26 deletions

View file

@ -39,7 +39,7 @@ endif
#---------------------------------------------------------------
override CPPFLAGS := -I$(srcdir) -I$(top_builddir)/src/interfaces/libpq $(CPPFLAGS) -DFRONTEND -DSYSCONFDIR='"$(sysconfdir)"' -DUSE_VERSION=$(USE_VERSION)
override CPPFLAGS := -g -I$(srcdir) -I$(top_builddir)/src/interfaces/libpq $(CPPFLAGS) -DFRONTEND -DSYSCONFDIR='"$(sysconfdir)"' -DUSE_VERSION=$(USE_VERSION)
all: shp2pgsql$(EXE) pgsql2shp$(EXE)

View file

@ -11,6 +11,9 @@
*
**********************************************************************
* $Log$
* Revision 1.12 2003/09/16 20:27:12 dblasby
* added ability to delete geometries.
*
* Revision 1.11 2003/08/08 18:19:20 dblasby
* Conformance changes.
* Removed junk from postgis_debug.c and added the first run of the long
@ -160,7 +163,6 @@ Datum lockcheck (PG_FUNCTION_ARGS)
{
TriggerData *trigdata = (TriggerData *) fcinfo->context;
char *colname ;
char *locktablename ;
int id;
HeapTuple rettuple;
TupleDesc tupdesc;
@ -168,6 +170,9 @@ Datum lockcheck (PG_FUNCTION_ARGS)
char *relname;
bool isnull;
char query[1024];
int pk_type_oid;
char *pk_id = NULL;
elog(NOTICE,"in lockcheck()");
@ -191,15 +196,54 @@ Datum lockcheck (PG_FUNCTION_ARGS)
colname = trigdata->tg_trigger->tgargs[0];
locktablename = trigdata->tg_trigger->tgargs[1];
elog(NOTICE,"trigger was executed on the relation: '%s', with attribute named '%s', with locktable named '%s'", relname,colname,locktablename);
elog(NOTICE,"trigger was executed on the relation: '%s', with attribute named '%s', with locktable named '%s'", relname,colname,"authorization_table");
//get the value
pk_type_oid =SPI_gettypeid ( tupdesc , SPI_fnumber(tupdesc,colname));
elog(NOTICE,"primary key type # = %i", pk_type_oid ) ;
if (pk_type_oid == 23) //int4
{
int id = (int) DatumGetInt32( SPI_getbinval(rettuple, tupdesc, SPI_fnumber(tupdesc,colname), &isnull) );
if (isnull)
{
elog(ERROR,"lockcheck - column (%s) of table (%s) is null!",colname,relname);
}
pk_id = palloc(100);
sprintf(pk_id,"%i",id);
}
else if (pk_type_oid == 25) // text
{
Datum id = ( SPI_getbinval(rettuple, tupdesc, SPI_fnumber(tupdesc,colname), &isnull) );
if (isnull)
{
elog(ERROR,"lockcheck - column (%s) of table (%s) is null!",colname,relname);
}
pk_id = DatumGetCString(DirectFunctionCall1(textout,id));
}
else if (pk_type_oid == 1043) // varchar
{
Datum id = ( SPI_getbinval(rettuple, tupdesc, SPI_fnumber(tupdesc,colname), &isnull) );
if (isnull)
{
elog(ERROR,"lockcheck - column (%s) of table (%s) is null!",colname,relname);
}
pk_id = DatumGetCString(DirectFunctionCall1(varcharout,id));
}
else
{
elog(ERROR,"id column (%s) of table (%s) has to be either int4, text, or varchar. Its - %s (oid %i)",colname,relname,SPI_gettype ( tupdesc , SPI_fnumber(tupdesc,colname) ) ,pk_type_oid );
}
id = (int) DatumGetInt32( SPI_getbinval(rettuple, tupdesc, SPI_fnumber(tupdesc,colname), &isnull) );
sprintf(query,"SELECT lock_key FROM %s WHERE expires >= now() AND id = %i", locktablename,id);
sprintf(query,"SELECT authid FROM %s WHERE expires >= now() AND tname = '%s' and fid = '%s'::text", "authorization_table",relname,pk_id);
elog(NOTICE,"about to execute :%s", query);
SPIcode = SPI_exec(query,0);
@ -228,11 +272,12 @@ Datum lockcheck (PG_FUNCTION_ARGS)
elog(NOTICE,"I do not own any locks (no lock table) - I cannot modify the row");
//PG_RETURN_NULL();
SPI_finish();
return NULL;
//return NULL;
elog(ERROR,"attemted to modify a locked row that I do not have authorization for!");
}
sprintf(query,"SELECT * FROM temp_lock_have_table WHERE xideq(transid , getTransactionID() ) AND lockcode =%s",lockcode);
sprintf(query,"SELECT * FROM temp_lock_have_table WHERE xideq(transid , getTransactionID() ) AND lockcode ='%s'",lockcode);
elog(NOTICE,"about to execute :%s", query);
SPIcode = SPI_exec(query,0);
@ -249,7 +294,8 @@ Datum lockcheck (PG_FUNCTION_ARGS)
elog(NOTICE,"I do not own the lock - I cannot modify the row");
//PG_RETURN_NULL();
SPI_finish();
return NULL;
//return NULL;
elog(ERROR,"attemted to modify a locked row that I do not have authorization for!");
}
else
{

View file

@ -11,6 +11,9 @@
*
**********************************************************************
* $Log$
* Revision 1.25 2003/09/16 20:27:12 dblasby
* added ability to delete geometries.
*
* Revision 1.24 2003/08/08 18:19:20 dblasby
* Conformance changes.
* Removed junk from postgis_debug.c and added the first run of the long
@ -2154,7 +2157,7 @@ Datum startpoint(PG_FUNCTION_ARGS)
LINE3D *line;
int32 *offsets1;
if (geom1->type != LINETYPE)
if ( (geom1->type != LINETYPE) && (geom1->type != MULTILINETYPE) )
PG_RETURN_NULL();
offsets1 = (int32 *) ( ((char *) &(geom1->objType[0] ))+ sizeof(int32) * geom1->nobjs ) ;
@ -2184,7 +2187,7 @@ Datum endpoint(PG_FUNCTION_ARGS)
if (geom1->type != LINETYPE)
if ( (geom1->type != LINETYPE) && (geom1->type != MULTILINETYPE) )
PG_RETURN_NULL();
offsets1 = (int32 *) ( ((char *) &(geom1->objType[0] ))+ sizeof(int32) * geom1->nobjs ) ;

View file

@ -10,6 +10,9 @@
*
**********************************************************************
* $Log$
* Revision 1.9 2003/09/16 20:27:12 dblasby
* added ability to delete geometries.
*
* Revision 1.8 2003/08/08 18:19:20 dblasby
* Conformance changes.
* Removed junk from postgis_debug.c and added the first run of the long
@ -418,10 +421,29 @@ Datum intersection(PG_FUNCTION_ARGS)
initGEOS(MAXIMUM_ALIGNOF);
elog(NOTICE,"intersection() START");
g1 = POSTGIS2GEOS(geom1 );
g2 = POSTGIS2GEOS(geom2 );
elog(NOTICE," constructed geometrys - calling geos");
//elog(NOTICE,"g1 = %s",GEOSasText(g1));
//elog(NOTICE,"g2 = %s",GEOSasText(g2));
if (g1==NULL)
elog(NOTICE,"g1 is null");
if (g2==NULL)
elog(NOTICE,"g2 is null");
//elog(NOTICE,"g2 is valid = %i",GEOSisvalid(g2));
//elog(NOTICE,"g1 is valid = %i",GEOSisvalid(g1));
g3 = GEOSIntersection(g1,g2);
elog(NOTICE," intersection finished");
if (g3 == NULL)
{
elog(ERROR,"GEOS Intersection() threw an error!");
@ -608,10 +630,11 @@ Datum overlaps(PG_FUNCTION_ARGS)
g1 = POSTGIS2GEOS(geom1 );
g2 = POSTGIS2GEOS(geom2 );
GEOSdeleteGeometry(g1);
GEOSdeleteGeometry(g2);
result = GEOSrelateOverlaps(g1,g2);
GEOSdeleteGeometry(g1);
GEOSdeleteGeometry(g2);
if (result == 2)
{
elog(ERROR,"GEOS overlaps() threw an error!");
@ -639,10 +662,12 @@ Datum contains(PG_FUNCTION_ARGS)
g1 = POSTGIS2GEOS(geom1 );
g2 = POSTGIS2GEOS(geom2 );
result = GEOSrelateContains(g1,g2);
GEOSdeleteGeometry(g1);
GEOSdeleteGeometry(g2);
result = GEOSrelateContains(g1,g2);
if (result == 2)
{
elog(ERROR,"GEOS contains() threw an error!");
@ -671,9 +696,11 @@ Datum within(PG_FUNCTION_ARGS)
g1 = POSTGIS2GEOS(geom1 );
g2 = POSTGIS2GEOS(geom2 );
result = GEOSrelateWithin(g1,g2);
GEOSdeleteGeometry(g1);
GEOSdeleteGeometry(g2);
result = GEOSrelateWithin(g1,g2);
if (result == 2)
{
elog(ERROR,"GEOS within() threw an error!");
@ -703,10 +730,13 @@ Datum crosses(PG_FUNCTION_ARGS)
g1 = POSTGIS2GEOS(geom1 );
g2 = POSTGIS2GEOS(geom2 );
result = GEOSrelateCrosses(g1,g2);
GEOSdeleteGeometry(g1);
GEOSdeleteGeometry(g2);
result = GEOSrelateCrosses(g1,g2);
if (result == 2)
{
elog(ERROR,"GEOS crosses() threw an error!");
@ -726,20 +756,23 @@ Datum intersects(PG_FUNCTION_ARGS)
GEOMETRY *geom1 = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
GEOMETRY *geom2 = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
Geometry *g1,*g2;
bool result;
errorIfGeometryCollection(geom1,geom2);
initGEOS(MAXIMUM_ALIGNOF);
g1 = POSTGIS2GEOS(geom1 );
g2 = POSTGIS2GEOS(geom2 );
GEOSdeleteGeometry(g1);
GEOSdeleteGeometry(g2);
result = GEOSrelateIntersects(g1,g2);
GEOSdeleteGeometry(g1);
GEOSdeleteGeometry(g2);
if (result == 2)
{
elog(ERROR,"GEOS intersects() threw an error!");
@ -768,10 +801,13 @@ Datum touches(PG_FUNCTION_ARGS)
g1 = POSTGIS2GEOS(geom1 );
g2 = POSTGIS2GEOS(geom2 );
result = GEOSrelateTouches(g1,g2);
GEOSdeleteGeometry(g1);
GEOSdeleteGeometry(g2);
result = GEOSrelateTouches(g1,g2);
if (result == 2)
{
elog(ERROR,"GEOS touches() threw an error!");

View file

@ -797,7 +797,7 @@ Geometry *GEOSpointonSurface(Geometry *g1)
void GEOSdeleteGeometry(Geometry *a)
{
try{
//
delete a;
}
catch(...)
{

View file

@ -8,9 +8,12 @@
*
* This is free software; you can redistribute and/or modify it under
* the terms of hte GNU General Public Licence. See the COPYING file.
*
*
**********************************************************************
* $Log$
* Revision 1.14 2003/09/16 20:27:12 dblasby
* added ability to delete geometries.
*
* Revision 1.13 2003/07/01 18:30:55 pramsey
* Added CVS revision headers.
*
@ -183,13 +186,13 @@ PJ *make_project(char *str1)
}
//tranform_geom( GEOMETRY, TEXT (input proj4), TEXT (input proj4), INT (output srid)
//tranform_geom( GEOMETRY, TEXT (input proj4), TEXT (output proj4), INT (output srid)
// tmpPts - if there is a nadgrid error (-38), we re-try the transform on a copy of points. The transformed points
// are in an indeterminate state after the -38 error is thrown.
PG_FUNCTION_INFO_V1(transform_geom);
Datum transform_geom(PG_FUNCTION_ARGS)
{
GEOMETRY *geom = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
GEOMETRY *geom ;
GEOMETRY *result;
PJ *input_pj,*output_pj;
@ -208,14 +211,22 @@ Datum transform_geom(PG_FUNCTION_ARGS)
text *input_proj4_text = (PG_GETARG_TEXT_P(1));
text *output_proj4_text = (PG_GETARG_TEXT_P(2));
int32 result_srid = PG_GETARG_INT32(3);
text *input_proj4_text;
text *output_proj4_text;
int32 result_srid ;
geom = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
input_proj4_text = (PG_GETARG_TEXT_P(1));
output_proj4_text = (PG_GETARG_TEXT_P(2));
result_srid = PG_GETARG_INT32(3);
input_proj4 = (char *) palloc(input_proj4_text->vl_len +1-4);
memcpy(input_proj4,input_proj4_text->vl_dat, input_proj4_text->vl_len-4);
input_proj4[input_proj4_text->vl_len-4] = 0; //null terminate
output_proj4 = (char *) palloc(output_proj4_text->vl_len +1-4);
memcpy(output_proj4,output_proj4_text->vl_dat, output_proj4_text->vl_len-4);
output_proj4[output_proj4_text->vl_len-4] = 0; //null terminate