Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS updates #7

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gdal/apps/ogr2ogr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2631,6 +2631,9 @@ static TargetLayerInfo* SetupTargetLayer( OGRDataSource *poSrcDS,
int iDstField = poDstFDefn->GetFieldIndex(poSrcFieldDefn->GetNameRef());
if (iDstField >= 0)
panMap[iField] = iDstField;
else
CPLDebug("OGR2OGR", "Skipping field '%s' not found in destination layer '%s'.",
poSrcFieldDefn->GetNameRef(), poDstLayer->GetName() );
}
}

Expand Down
10 changes: 7 additions & 3 deletions gdal/ogr/gml2ogrgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ OGRGeometry *GML2OGRGeometry_XMLNode( const CPLXMLNode *psNode,

int nSign = (det >= 0) ? 1 : -1;

double alpha;
double alpha, dfRemainder;
double dfStep = atof(CPLGetConfigOption("OGR_ARC_STEPSIZE","4")) / 180 * PI;

// make sure the segments are not too short
Expand Down Expand Up @@ -915,16 +915,20 @@ OGRGeometry *GML2OGRGeometry_XMLNode( const CPLXMLNode *psNode,

dfStep *= nSign;

dfRemainder = fmod(alpha1 - alpha0, dfStep) / 2.0;

poLine->addPoint(x0, y0);

for(alpha = alpha0 + dfStep; (alpha - alpha1) * nSign < 0; alpha += dfStep)
for(alpha = alpha0 + dfStep + dfRemainder; (alpha + dfRemainder - alpha1) * nSign < 0; alpha += dfStep)
{
poLine->addPoint(cx + R * cos(alpha), cy + R * sin(alpha));
}

poLine->addPoint(x1, y1);

for(alpha = alpha1 + dfStep; (alpha - alpha2) * nSign < 0; alpha += dfStep)
dfRemainder = fmod(alpha2 - alpha1, dfStep) / 2.0;

for(alpha = alpha1 + dfStep + dfRemainder; (alpha + dfRemainder - alpha2) * nSign < 0; alpha += dfStep)
{
poLine->addPoint(cx + R * cos(alpha), cy + R * sin(alpha));
}
Expand Down
2 changes: 1 addition & 1 deletion gdal/ogr/ogrsf_frmts/nas/nashandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ void NASHandler::endElement(const XMLCh* const uri,
{
int iId = poState->m_poFeature->GetClass()->GetPropertyIndex( "gml_id" );
const GMLProperty *poIdProp = poState->m_poFeature->GetProperty(iId);
#if DEBUG_VERBOSE
#ifdef DEBUG_VERBOSE
char *pszOldGeom = CPLSerializeXMLTree( poState->m_poFeature->GetGeometryList()[0] );

CPLDebug("NAS", "Overwriting other geometry (%s; replace:%s; with:%s)",
Expand Down
15 changes: 0 additions & 15 deletions gdal/ogr/ogrsf_frmts/nas/nasreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,21 +625,6 @@ void NASReader::SetFeaturePropertyDirectly( const char *pszElement,
}
return;
}
#if 0
else if( strcmp(poClass->GetProperty(iProperty)->GetName(),"signaturnummer") == 0 ||
strcmp(poClass->GetProperty(iProperty)->GetName(),"anlass") == 0 )
{
if( isalpha( pszValue[0] ) && isalpha( pszValue[1] ) && isdigit( pszValue[2] ) )
{
poFeature->SetPropertyDirectly( iProperty, CPLStrdup( pszValue+2 ) );
#ifdef DEBUG_VERBOSE
CPLDebug( "NAS", "Skipping two letter prefix of '%s'", pszValue );
#endif
CPLFree(pszValue);
return;
}
}
#endif
else if( strcmp(poClass->GetProperty(iProperty)->GetName(),"kartendarstellung") == 0 ||
strcmp(poClass->GetProperty(iProperty)->GetName(),"rechtsbehelfsverfahren") == 0 )
{
Expand Down
72 changes: 37 additions & 35 deletions gdal/ogr/ogrsf_frmts/nas/ogrnasdatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@

CPL_CVSID("$Id$");

static const char *apszURNNames[] =
{
"DE_DHDN_3GK2_*", "EPSG:31466",
"DE_DHDN_3GK3_*", "EPSG:31467",
"ETRS89_UTM32", "EPSG:25832",
NULL, NULL
static const char *apszURNNames[] =
{
"DE_DHDN_3GK2_*", "EPSG:31466",
"DE_DHDN_3GK3_*", "EPSG:31467",
"ETRS89_UTM32", "EPSG:25832",
"ETRS89_UTM33", "EPSG:25833",
NULL, NULL
};

/************************************************************************/
Expand Down Expand Up @@ -66,7 +67,7 @@ OGRNASDataSource::~OGRNASDataSource()

for( int i = 0; i < nLayers; i++ )
delete papoLayers[i];

CPLFree( papoLayers );

if( poReader )
Expand All @@ -90,8 +91,8 @@ int OGRNASDataSource::Open( const char * pszNewName, int bTestOpen )
if( fp == NULL )
{
if( !bTestOpen )
CPLError( CE_Failure, CPLE_OpenFailed,
"Failed to open NAS file `%s'.",
CPLError( CE_Failure, CPLE_OpenFailed,
"Failed to open NAS file `%s'.",
pszNewName );

return FALSE;
Expand All @@ -114,7 +115,7 @@ int OGRNASDataSource::Open( const char * pszNewName, int bTestOpen )
/* -------------------------------------------------------------------- */
/* Check for a UTF-8 BOM and skip if found */
/* */
/* TODO: BOM is variable-lenght parameter and depends on encoding. */
/* TODO: BOM is variable-length parameter and depends on encoding. */
/* Add BOM detection for other encodings. */
/* -------------------------------------------------------------------- */

Expand All @@ -131,34 +132,35 @@ int OGRNASDataSource::Open( const char * pszNewName, int bTestOpen )
/* -------------------------------------------------------------------- */
/* Here, we expect the opening chevrons of NAS tree root element */
/* -------------------------------------------------------------------- */
if( szPtr[0] != '<'
|| strstr(szPtr,"opengis.net/gml") == NULL
|| strstr(szPtr,"NAS-Operationen.xsd") == NULL )
if( szPtr[0] != '<'
|| strstr(szPtr,"opengis.net/gml") == NULL
|| (strstr(szPtr,"NAS-Operationen.xsd") == NULL &&
strstr(szPtr,"AAA-Fachschema.xsd") == NULL ) )
{
VSIFClose( fp );
return FALSE;
}
}

/* -------------------------------------------------------------------- */
/* We assume now that it is NAS. Close and instantiate a */
/* NASReader on it. */
/* -------------------------------------------------------------------- */
VSIFClose( fp );

poReader = CreateNASReader();
if( poReader == NULL )
{
CPLError( CE_Failure, CPLE_AppDefined,
CPLError( CE_Failure, CPLE_AppDefined,
"File %s appears to be NAS but the NAS reader can't\n"
"be instantiated, likely because Xerces support wasn't\n"
"configured in.",
"configured in.",
pszNewName );
return FALSE;
}

poReader->SetSourceFile( pszNewName );

pszName = CPLStrdup( pszNewName );

/* -------------------------------------------------------------------- */
Expand All @@ -175,9 +177,9 @@ int OGRNASDataSource::Open( const char * pszNewName, int bTestOpen )

if( sNASStatBuf.st_mtime > sGFSStatBuf.st_mtime )
{
CPLDebug( "NAS",
CPLDebug( "NAS",
"Found %s but ignoring because it appears\n"
"be older than the associated NAS file.",
"be older than the associated NAS file.",
pszGFSFilename );
}
else
Expand All @@ -192,8 +194,8 @@ int OGRNASDataSource::Open( const char * pszNewName, int bTestOpen )
/* information. */
/* -------------------------------------------------------------------- */
CPLErrorReset();
if( !bHaveSchema
&& !poReader->PrescanForSchema( TRUE )
if( !bHaveSchema
&& !poReader->PrescanForSchema( TRUE )
&& CPLGetLastErrorType() == CE_Failure )
{
// we assume an errors have been reported.
Expand All @@ -209,15 +211,15 @@ int OGRNASDataSource::Open( const char * pszNewName, int bTestOpen )
FILE *fp = NULL;

pszGFSFilename = CPLResetExtension( pszNewName, "gfs" );
if( CPLStat( pszGFSFilename, &sGFSStatBuf ) != 0
if( CPLStat( pszGFSFilename, &sGFSStatBuf ) != 0
&& (fp = VSIFOpen( pszGFSFilename, "wt" )) != NULL )
{
VSIFClose( fp );
poReader->SaveClasses( pszGFSFilename );
}
else
{
CPLDebug("NAS",
CPLDebug("NAS",
"Not saving %s files already exists or can't be created.",
pszGFSFilename );
}
Expand All @@ -235,7 +237,7 @@ int OGRNASDataSource::Open( const char * pszNewName, int bTestOpen )
papoLayers[nLayers] = TranslateNASSchema(poReader->GetClass(nLayers));
nLayers++;
}

poRelationLayer = new OGRNASRelationLayer( this );

// keep delete the last layer
Expand All @@ -250,7 +252,7 @@ int OGRNASDataSource::Open( const char * pszNewName, int bTestOpen )
}

nLayers++;

return TRUE;
}

Expand All @@ -262,7 +264,7 @@ OGRNASLayer *OGRNASDataSource::TranslateNASSchema( GMLFeatureClass *poClass )

{
OGRNASLayer *poLayer;
OGRwkbGeometryType eGType
OGRwkbGeometryType eGType
= (OGRwkbGeometryType) poClass->GetGeometryType();

if( poClass->GetFeatureCount() == 0 )
Expand All @@ -278,7 +280,7 @@ OGRNASLayer *OGRNASDataSource::TranslateNASSchema( GMLFeatureClass *poClass )
int i;

poSRS = new OGRSpatialReference();

const char *pszHandle = strrchr( pszSRSName, ':' );
if( pszHandle != NULL )
pszHandle += 1;
Expand All @@ -300,10 +302,10 @@ OGRNASLayer *OGRNASDataSource::TranslateNASSchema( GMLFeatureClass *poClass )
pszSRSName = apszURNNames[i*2+1];
}
}

if (poSRS->SetFromUserInput(pszSRSName) != OGRERR_NONE)
{
CPLDebug( "NAS", "Failed to translate srsName='%s'",
CPLDebug( "NAS", "Failed to translate srsName='%s'",
pszSRSName );
delete poSRS;
poSRS = NULL;
Expand Down Expand Up @@ -340,7 +342,7 @@ OGRNASLayer *OGRNASDataSource::TranslateNASSchema( GMLFeatureClass *poClass )
eFType = OFTRealList;
else
eFType = OFTString;

OGRFieldDefn oField( poProperty->GetName(), eFType );
if ( EQUALN(oField.GetNameRef(), "ogr:", 4) )
oField.SetName(poProperty->GetName()+4);
Expand Down Expand Up @@ -397,19 +399,19 @@ void OGRNASDataSource::PopulateRelations()
int nGMLIdIndex = poFeature->GetClass()->GetPropertyIndex( "gml_id" );
const GMLProperty *psGMLId = (nGMLIdIndex >= 0) ? poFeature->GetProperty(nGMLIdIndex ) : NULL;
char *pszName = NULL;
const char *pszValue = CPLParseNameValue( papszOBProperties[i],
const char *pszValue = CPLParseNameValue( papszOBProperties[i],
&pszName );

if( EQUALN(pszValue,"urn:adv:oid:",12)
if( EQUALN(pszValue,"urn:adv:oid:",12)
&& psGMLId != NULL && psGMLId->nSubProperties == 1 )
{
poRelationLayer->AddRelation( psGMLId->papszSubProperties[0],
pszName,
pszName,
pszValue + 12 );
}
CPLFree( pszName );
}

delete poFeature;
}

Expand Down
3 changes: 3 additions & 0 deletions gdal/ogr/ogrsf_frmts/oci/ogr_oci.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ class OGROCITableLayer : public OGROCIWritableLayer

// following methods are not base class overrides
int IsValid() { return bValidTable; }

int GetMaxFID();
};

/************************************************************************/
Expand Down Expand Up @@ -516,6 +518,7 @@ class OGROCIDataSource : public OGRDataSource
const char *GetName() { return pszName; }
int GetLayerCount() { return nLayers; }
OGRLayer *GetLayer( int );
OGRLayer *GetLayerByName(const char * pszName);

virtual OGRErr DeleteLayer(int);
virtual OGRLayer *CreateLayer( const char *,
Expand Down
48 changes: 47 additions & 1 deletion gdal/ogr/ogrsf_frmts/oci/ogrocidatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ void OGROCIDataSource::DeleteLayer( const char *pszLayerName )
if( iLayer == nLayers )
{
CPLDebug( "OCI", "DeleteLayer: %s not found in layer list." \
" Layer * not* deleted.", pszLayerName );
" Layer *not* deleted.", pszLayerName );
return;
}

Expand Down Expand Up @@ -964,3 +964,49 @@ int OGROCIDataSource::FetchSRSId( OGRSpatialReference * poSRS )
else
return nSRSId;
}


/************************************************************************/
/* GetLayerByName() */
/************************************************************************/

OGRLayer *OGROCIDataSource::GetLayerByName( const char *pszName )

{
OGROCILayer *poLayer;
int i, count;

if ( !pszName )
return NULL;

count = GetLayerCount();

/* first a case sensitive check */
for( i = 0; i < count; i++ )
{
poLayer = papoLayers[i];

if( strcmp( pszName, poLayer->GetName() ) == 0 )
{
return poLayer;
}
}

char *pszSafeLayerName = CPLStrdup( pszName );
poSession->CleanName( pszSafeLayerName );

/* then case insensitive and laundered */
for( i = 0; i < count; i++ )
{
poLayer = papoLayers[i];

if( EQUAL( pszSafeLayerName, poLayer->GetName() ) )
{
break;
}
}

CPLFree( pszSafeLayerName );

return i < count ? poLayer : NULL;
}
Loading