⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ogrgmldatasource.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************** * $Id: ogrgmldatasource.cpp,v 1.17 2005/01/27 16:34:56 fwarmerdam Exp $ * * Project:  OGR * Purpose:  Implements OGRGMLDataSource class. * Author:   Frank Warmerdam, warmerdam@pobox.com * ****************************************************************************** * Copyright (c) 2002, Frank Warmerdam <warmerdam@pobox.com> * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. ****************************************************************************** * * $Log: ogrgmldatasource.cpp,v $ * Revision 1.17  2005/01/27 16:34:56  fwarmerdam * Fixed gml test.  Don't try to read any old XML file! * * Revision 1.16  2005/01/27 04:06:32  fwarmerdam * added 3L0 XSD support * * Revision 1.15  2004/01/29 15:30:40  warmerda * cleanup layer and field names * * Revision 1.14  2004/01/15 20:53:16  warmerda * Ensure that ogr namespace is defined. * * Revision 1.13  2003/05/21 03:48:35  warmerda * Expand tabs * * Revision 1.12  2003/04/03 16:23:49  warmerda * Added support for XSISCHEMA creation option which may be INTERNAL, EXTERNAL * or OFF.  EXTERNAL (write an associated .xsd file) is the default. * * Revision 1.11  2003/03/13 14:40:00  warmerda * added missing xs:sequence * * Revision 1.10  2003/03/11 01:26:35  warmerda * Fixed redeclared variable. * * Revision 1.9  2003/03/07 14:53:21  warmerda * implement preliminary BXFS write support * * Revision 1.8  2003/01/22 17:20:24  warmerda * fixed xsi:schemaLocation output * * Revision 1.7  2003/01/17 20:40:06  warmerda * added bounding rectangle support and XSISCHEMAURI option * * Revision 1.6  2003/01/07 22:30:18  warmerda * Added special support for output filename "stdout". * * Revision 1.5  2002/08/15 15:26:12  warmerda * Properly close file if test open fails. * * Revision 1.4  2002/03/06 20:08:47  warmerda * save/use .gfs file by default * * Revision 1.3  2002/01/25 20:54:23  warmerda * fixed last fix * * Revision 1.2  2002/01/25 20:46:26  warmerda * recover if CreateGMLReader() fails * * Revision 1.1  2002/01/25 20:37:02  warmerda * New * */#include "ogr_gml.h"#include "cpl_conv.h"#include "cpl_string.h"CPL_CVSID("$Id: ogrgmldatasource.cpp,v 1.17 2005/01/27 16:34:56 fwarmerdam Exp $");/************************************************************************//*                         OGRGMLDataSource()                         *//************************************************************************/OGRGMLDataSource::OGRGMLDataSource(){    pszName = NULL;    papoLayers = NULL;    nLayers = 0;    poReader = NULL;    fpOutput = NULL;    papszCreateOptions = NULL;}/************************************************************************//*                        ~OGRGMLDataSource()                         *//************************************************************************/OGRGMLDataSource::~OGRGMLDataSource(){    if( fpOutput != NULL )    {        VSIFPrintf( fpOutput, "%s",                     "</ogr:FeatureCollection>\n" );        InsertHeader();        if( nBoundedByLocation != -1             && sBoundingRect.IsInit()             && VSIFSeek( fpOutput, nBoundedByLocation, SEEK_SET ) == 0 )        {            VSIFPrintf( fpOutput, "  <gml:boundedBy>\n" );            VSIFPrintf( fpOutput, "    <gml:Box>\n" );            VSIFPrintf( fpOutput,                         "      <gml:coord><gml:X>%.16g</gml:X>"                        "<gml:Y>%.16g</gml:Y></gml:coord>\n",                        sBoundingRect.MinX, sBoundingRect.MinY );            VSIFPrintf( fpOutput,                         "      <gml:coord><gml:X>%.16g</gml:X>"                        "<gml:Y>%.16g</gml:Y></gml:coord>\n",                        sBoundingRect.MaxX, sBoundingRect.MaxY );            VSIFPrintf( fpOutput, "    </gml:Box>\n" );            VSIFPrintf( fpOutput, "  </gml:boundedBy>" );        }        if( fpOutput != stdout )            VSIFClose( fpOutput );    }    CSLDestroy( papszCreateOptions );    CPLFree( pszName );    for( int i = 0; i < nLayers; i++ )        delete papoLayers[i];        CPLFree( papoLayers );}/************************************************************************//*                                Open()                                *//************************************************************************/int OGRGMLDataSource::Open( const char * pszNewName, int bTestOpen ){    FILE        *fp;    char        szHeader[1000];/* -------------------------------------------------------------------- *//*      Open the source file.                                           *//* -------------------------------------------------------------------- */    fp = VSIFOpen( pszNewName, "r" );    if( fp == NULL )    {        if( !bTestOpen )            CPLError( CE_Failure, CPLE_OpenFailed,                       "Failed to open GML file `%s'.",                       pszNewName );        return FALSE;    }/* -------------------------------------------------------------------- *//*      If we aren't sure it is GML, load a header chunk and check      *//*      for signs it is GML                                             *//* -------------------------------------------------------------------- */    if( bTestOpen )    {        VSIFRead( szHeader, 1, sizeof(szHeader), fp );        szHeader[sizeof(szHeader)-1] = '\0';        if( szHeader[0] != '<'             || strstr(szHeader,"opengis.net/gml") == NULL )        {            VSIFClose( fp );            return FALSE;        }    }    /* -------------------------------------------------------------------- *//*      We assume now that it is GML.  Close and instantiate a          *//*      GMLReader on it.                                                *//* -------------------------------------------------------------------- */    VSIFClose( fp );        poReader = CreateGMLReader();    if( poReader == NULL )    {        CPLError( CE_Failure, CPLE_AppDefined,                   "File %s appears to be GML but the GML reader can't\n"                  "be instantiated, likely because Xerces support wasn't\n"                  "configured in.",                   pszNewName );        return FALSE;    }    poReader->SetSourceFile( pszNewName );        pszName = CPLStrdup( pszNewName );/* -------------------------------------------------------------------- *//*      Can we find a GML Feature Schema (.gfs) for the input file?     *//* -------------------------------------------------------------------- */    const char *pszGFSFilename;    VSIStatBuf sGFSStatBuf, sGMLStatBuf;    int        bHaveSchema = FALSE;    pszGFSFilename = CPLResetExtension( pszNewName, "gfs" );    if( CPLStat( pszGFSFilename, &sGFSStatBuf ) == 0 )    {        CPLStat( pszNewName, &sGMLStatBuf );        if( sGMLStatBuf.st_mtime > sGFSStatBuf.st_mtime )        {            CPLDebug( "GML",                       "Found %s but ignoring because it appears\n"                      "be older than the associated GML file.",                       pszGFSFilename );        }        else        {            bHaveSchema = poReader->LoadClasses( pszGFSFilename );        }    }/* -------------------------------------------------------------------- *//*      Can we find an xsd which might conform to tbe GML3 Level 0      *//*      profile?  We really ought to look for it based on the rules     *//*      schemaLocation in the GML feature collection but for now we     *//*      just hopes it is in the same director with the same name.       *//* -------------------------------------------------------------------- */    const char *pszXSDFilename;    if( !bHaveSchema )    {        pszXSDFilename = CPLResetExtension( pszNewName, "xsd" );        if( CPLStat( pszXSDFilename, &sGMLStatBuf ) == 0 )        {            bHaveSchema = poReader->ParseXSD( pszXSDFilename );        }    }    /* -------------------------------------------------------------------- *//*      Force a first pass to establish the schema.  Eventually we      *//*      will have mechanisms for remembering the schema and related     *//*      information.                                                    *//* -------------------------------------------------------------------- */    if( !bHaveSchema && !poReader->PrescanForSchema( TRUE ) )    {        // we assume an errors have been reported.        return FALSE;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -