OGRErr OGRMultiPoint::importFromWkt_Bracketed( char ** ppszInput ) { char szToken[OGR_WKT_TOKEN_MAX]; const char *pszInput = *ppszInput; OGRErr eErr = OGRERR_NONE; /* -------------------------------------------------------------------- */ /* Skip MULTIPOINT keyword. */ /* -------------------------------------------------------------------- */ pszInput = OGRWktReadToken( pszInput, szToken ); /* -------------------------------------------------------------------- */ /* Read points till we get to the closing bracket. */ /* -------------------------------------------------------------------- */ int nMaxPoint = 0; int nPointCount = 0; OGRRawPoint *paoPoints = NULL; double *padfZ = NULL; while( (pszInput = OGRWktReadToken( pszInput, szToken )) && (EQUAL(szToken,"(") || EQUAL(szToken,",")) ) { OGRGeometry *poGeom; pszInput = OGRWktReadPoints( pszInput, &paoPoints, &padfZ, &nMaxPoint, &nPointCount ); if( pszInput == NULL || nPointCount != 1 ) return OGRERR_CORRUPT_DATA; if( padfZ ) poGeom = new OGRPoint( paoPoints[0].x, paoPoints[0].y, padfZ[0] ); else poGeom = new OGRPoint( paoPoints[0].x, paoPoints[0].y ); eErr = addGeometryDirectly( poGeom ); if( eErr != OGRERR_NONE ) return eErr; } /* -------------------------------------------------------------------- */ /* Cleanup. */ /* -------------------------------------------------------------------- */ OGRFree( paoPoints ); if( padfZ ) OGRFree( padfZ ); if( !EQUAL(szToken,")") ) return OGRERR_CORRUPT_DATA; *ppszInput = (char *) pszInput; return OGRERR_NONE; }
OGRLineString::~OGRLineString() { if( paoPoints != NULL ) OGRFree( paoPoints ); if( padfZ != NULL ) OGRFree( padfZ ); }
void Polygon::update(const std::string& wkt_or_json, SpatialReference ref) { bool isJson = wkt_or_json.find("{") != wkt_or_json.npos || wkt_or_json.find("}") != wkt_or_json.npos; if (!isJson) { m_geom = GEOSGeomFromWKT_r(m_ctx, wkt_or_json.c_str()); if (!m_geom) throw pdal_error("Unable to create geometry from input WKT"); } else { // Assume it is GeoJSON and try constructing from that OGRGeometryH json = OGR_G_CreateGeometryFromJson(wkt_or_json.c_str()); if (!json) throw pdal_error("Unable to create geometry from " "input GeoJSON"); char* gdal_wkt(0); OGRErr err = OGR_G_ExportToWkt(json, &gdal_wkt); m_geom = GEOSGeomFromWKT_r(m_ctx, gdal_wkt); //ABELL - Why should this ever throw? Is it worth catching if // we don't know why? if (!m_geom) throw pdal_error("Unable to create GEOS geometry from OGR WKT!"); OGRFree(gdal_wkt); OGR_G_DestroyGeometry(json); } prepare(); }
rspfProjection* rspfOgrVectorTileSource::createProjFromReference(OGRSpatialReference* reference)const { if(traceDebug()) { rspfNotify(rspfNotifyLevel_DEBUG) << "rspfOgrVectorTileSource::createProjFromReference: entered........" << std::endl; } if(!reference) { if(traceDebug()) { rspfNotify(rspfNotifyLevel_DEBUG) << "rspfOgrVectorTileSource::createProjFromReference: leaving........" << std::endl; } return 0; } char* wktString = 0; rspfKeywordlist kwl; reference->exportToWkt(&wktString); wktTranslator.toOssimKwl(wktString, kwl); if(traceDebug()) { rspfNotify(rspfNotifyLevel_DEBUG) << "wktString === " << wktString << std::endl; rspfNotify(rspfNotifyLevel_DEBUG) << "KWL === " << kwl << std::endl; } OGRFree(wktString); if(traceDebug()) { rspfNotify(rspfNotifyLevel_DEBUG) << "rspfOgrVectorTileSource::createProjFromReference: returning........" << std::endl; } return rspfProjectionFactoryRegistry::instance()->createProjection(kwl); }
/* OGR_G_ExportToWkt(OGRGeometryH, char **) {ok, DataSource} = lgeo_ogr:open("test/polygon.shp"), {ok, Layer} = lgeo_ogr:ds_get_layer(DataSource, 0), {ok, Feature} = lgeo_ogr:l_get_feature(Layer, 0), {ok, Geometry} = lgeo_ogr:f_get_geometry_ref(Feature), {ok, Wkt} = lgeo_ogr:g_export_to_wkt(Geometry). */ static ERL_NIF_TERM g_export_to_wkt(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { EnvGeometry_t **geom; ERL_NIF_TERM eterm; if (argc != 1) { return enif_make_badarg(env); } if (!enif_get_resource(env, argv[0], OGR_G_RESOURCE, (void**)&geom)) { return enif_make_badarg(env); } char *wkt = NULL; OGRErr eErr = OGR_G_ExportToWkt((**geom).obj, &wkt); if (eErr != OGRERR_NONE) { return enif_make_tuple2(env, enif_make_atom(env, "error"), enif_make_int(env, eErr)); } eterm = enif_make_string(env, wkt, ERL_NIF_LATIN1); OGRFree(wkt); return enif_make_tuple2(env, enif_make_atom(env, "ok"), eterm); }
/* OGR_G_ExportToWkb (OGRGeometryH, OGRwkbByteOrder, unsigned char *) {ok, DataSource} = lgeo_ogr:open("test/polygon.shp"), {ok, Layer} = lgeo_ogr:ds_get_layer(DataSource, 0), {ok, Feature} = lgeo_ogr:l_get_feature(Layer, 0), {ok, Geometry} = lgeo_ogr:f_get_geometry_ref(Feature), {ok, Wkb} = lgeo_ogr:g_export_to_wkb(Geometry). */ static ERL_NIF_TERM g_export_to_wkb(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { EnvGeometry_t **geom; ERL_NIF_TERM eterm; if (argc != 1) { return enif_make_badarg(env); } if (!enif_get_resource(env, argv[0], OGR_G_RESOURCE, (void**)&geom)) { return enif_make_badarg(env); } int size = OGR_G_WkbSize((**geom).obj); unsigned char *wkb = malloc(sizeof(char)*(size)); OGRErr eErr = OGR_G_ExportToWkb((**geom).obj, (OGRwkbByteOrder)(( htonl( 1 ) == 1 ) ? 0 : 1), wkb); if (eErr != OGRERR_NONE) { return enif_make_tuple2(env, enif_make_atom(env, "error"), enif_make_int(env, eErr)); } ErlNifBinary bin = {.size = size, .data = wkb}; eterm = enif_make_binary(env, &bin); OGRFree(wkb); return enif_make_tuple2(env, enif_make_atom(env, "ok"), eterm); }
/** * Write the TIN to a TIN (.itf) file (VTP-defined format). */ bool vtTin::Write(const char *fname, bool progress_callback(int)) const { FILE *fp = vtFileOpen(fname, "wb"); if (!fp) return false; char *wkt; OGRErr err = m_proj.exportToWkt(&wkt); if (err != OGRERR_NONE) { fclose(fp); return false; } int proj_len = strlen(wkt); int data_start = 5 + 4 + 4 + 4 + + 4 + proj_len + 32 + 4 + 4; int i; int verts = NumVerts(); int tris = NumTris(); fwrite("tin02", 5, 1, fp); // version 2 fwrite(&verts, 4, 1, fp); fwrite(&tris, 4, 1, fp); fwrite(&data_start, 4, 1, fp); fwrite(&proj_len, 4, 1, fp); fwrite(wkt, proj_len, 1, fp); OGRFree(wkt); // version 2 of the format has extents: left, top, right, bottom, min z, max h fwrite(&m_EarthExtents.left, sizeof(double), 4, fp); fwrite(&m_fMinHeight, sizeof(float), 1, fp); fwrite(&m_fMaxHeight, sizeof(float), 1, fp); // room for future extention: you can add fields here, as long as you // increase the data_start offset above accordingly // count progress int count = 0, total = verts + tris; // write verts for (i = 0; i < verts; i++) { fwrite(&m_vert[i].x, 8, 2, fp); // 2 doubles fwrite(&m_z[i], 4, 1, fp); // 1 float if (progress_callback && (++count % 100) == 0) progress_callback(count * 99 / total); } // write tris for (i = 0; i < tris; i++) { fwrite(&m_tri[i*3], 4, 3, fp); // 3 ints if (progress_callback && (++count % 100) == 0) progress_callback(count * 99 / total); } fclose(fp); return true; }
bool vtStructureArray::WriteXML(const char* filename, bool bGZip) const { VTLOG("WriteXML(%s)\n", filename); // Avoid trouble with '.' and ',' in Europe LocaleWrap normal_numbers(LC_NUMERIC, "C"); GZOutput out(bGZip); if (!gfopen(out, filename)) { throw xh_io_exception("Could not open output file", xh_location(filename), "XML Writer"); } gfprintf(out, "<?xml version=\"1.0\"?>\n"); gfprintf(out, "\n"); gfprintf(out, "<StructureCollection xmlns=\"http://www.openplans.net\"\n" "\t\t\t\t\t xmlns:gml=\"http://www.opengis.net/gml\"\n" "\t\t\t\t\t xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n" "\t\t\t\t\t xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" "\t\t\t\t\t xsi:schemaLocation=\"http://www.openplans.net/buildings.xsd\">\n"); gfprintf(out, "\n"); // Write the extents (required by gml:StructureCollection) DRECT ext; GetExtents(ext); gfprintf(out, "\t<gml:boundedBy>\n"); gfprintf(out, "\t\t<gml:Box>\n"); gfprintf(out, "\t\t\t<gml:coordinates>"); gfprintf(out, "%.9lf,%.9lf %.9lf,%.9lf", ext.left, ext.bottom, ext.right, ext.top); gfprintf(out, "</gml:coordinates>\n"); gfprintf(out, "\t\t</gml:Box>\n"); gfprintf(out, "\t</gml:boundedBy>\n"); gfprintf(out, "\n"); // Write projection char *wkt; OGRErr err = m_proj.exportToWkt(&wkt); if (err != OGRERR_NONE) { throw xh_io_exception("Couldn't write CRS to file", xh_location(filename), "XML Writer"); } gfprintf(out, "\t<SRS>%s</SRS>\n", wkt); gfprintf(out, "\n"); OGRFree(wkt); bool bDegrees = (m_proj.IsGeographic() == 1); for (uint i = 0; i < GetSize(); i++) { vtStructure *str = GetAt(i); str->WriteXML(out, bDegrees); } gfprintf(out, "</StructureCollection>\n"); gfclose(out); return true; }
QString MapReprojector::toWkt(OGRSpatialReference* srs) { char* wkt = 0; srs->exportToWkt(&wkt); QString result = QString::fromUtf8(wkt); OGRFree(wkt); return result; }
QgsOgrMapToPixelSimplifier::~QgsOgrMapToPixelSimplifier() { if ( mPointBufferPtr ) { OGRFree( mPointBufferPtr ); mPointBufferPtr = NULL; } }
void dump_geometry(std::vector<unsigned char> &wkb){ CV::Util::Geometry::OGRGeomPtr gg(wkb); char *txt=NULL; gg->exportToWkt(&txt); std::cout << std::string(txt) ; // free allocated memory OGRFree(txt); }
void OGRLineString::Make2D() { if( padfZ != NULL ) { OGRFree( padfZ ); padfZ = NULL; } }
static dErr JakoViewWKT(OGRSpatialReferenceH ref,const char *name,PetscViewer viewer) { dErr err; OGRErr oerr; char *wkt; dFunctionBegin; oerr = OSRExportToPrettyWkt(ref,&wkt,0);dOGRCHK(oerr); err = PetscViewerASCIIPrintf(viewer,"WKT %s: %s\n\n",name,wkt);dCHK(err); OGRFree(wkt); dFunctionReturn(0); }
QString QgsCoordinateReferenceSystem::toWkt() const { QString myWkt; char* Wkt; if ( OSRExportToWkt( mCRS, &Wkt ) == OGRERR_NONE ) { myWkt = Wkt; OGRFree( Wkt ); } return myWkt; }
//! Returns a point buffer of the specified size OGRRawPoint* QgsOgrMapToPixelSimplifier::mallocPoints( int numPoints ) { if ( mPointBufferPtr && mPointBufferCount < numPoints ) { OGRFree( mPointBufferPtr ); mPointBufferPtr = NULL; } if ( mPointBufferPtr == NULL ) { mPointBufferCount = numPoints; mPointBufferPtr = ( OGRRawPoint* )OGRMalloc( mPointBufferCount * sizeof( OGRRawPoint ) ); } return mPointBufferPtr; }
GDALDataset* CreateGDALRaster(TeRasterParams& params) { // Gets the appropriate GDAL driver std::string path = params.fileName_; if(path.empty()) return 0; std::string extension = TeGetExtension(path.c_str()); std::string driverName = TeGDALDecoder::getGDALDriverName(extension); if(driverName.empty()) return 0; GDALDriverManager* driverManager = GetGDALDriverManager(); GDALDriver* driver = driverManager->GetDriverByName(driverName.c_str()); if(driver == 0) return 0; // Converts the raster data type GDALDataType gDataType = Convert2GDAL(params.dataType_[0]); // Creates the raster GDAL GDALDataset* ds = driver->Create(path.c_str(), params.ncols_, params.nlines_, params.nBands(), gDataType, 0); if(ds == 0) return 0; // Sets the geometric transformations double gt[6]; Convert2GDAL(gt, params); ds->SetGeoTransform(gt); // Sets the raster projection TeProjection* proj = params.projection(); if(proj) { int epsg = proj->epsgCode(); OGRSpatialReference oSRS; oSRS.importFromEPSG(epsg); char* projWKT = 0; if(oSRS.exportToWkt(&projWKT) == OGRERR_NONE) { ds->SetProjection(projWKT); OGRFree(projWKT); } } return ds; }
void OffsetWorker::run() { std::auto_ptr< SFCGAL::Geometry > g( SFCGAL::io::readWkt(wkt_poly)); OGRFree(wkt_poly); //Not needed after here switch ( g->geometryTypeId() ) { case SFCGAL::TYPE_POLYGON: break; default: return; } SFCGAL::Polygon poly = g->as<SFCGAL::Polygon>(); Polygon_2 p = poly.toPolygon_2(true); this->offsetPolygon(p, offset); }
void OGRPolygon::empty() { if( papoRings != NULL ) { for( int i = 0; i < nRingCount; i++ ) { delete papoRings[i]; } OGRFree( papoRings ); } papoRings = NULL; nRingCount = 0; }
void OGRGeometryCollection::empty() { if( papoGeoms != NULL ) { for( int i = 0; i < nGeomCount; i++ ) { delete papoGeoms[i]; } OGRFree( papoGeoms ); } nGeomCount = 0; papoGeoms = NULL; }
void OGRLineString::setNumPoints( int nNewPointCount ) { if( nNewPointCount == 0 ) { OGRFree( paoPoints ); paoPoints = NULL; OGRFree( padfZ ); padfZ = NULL; nPointCount = 0; return; } if( nNewPointCount > nPointCount ) { paoPoints = (OGRRawPoint *) OGRRealloc(paoPoints, sizeof(OGRRawPoint) * nNewPointCount); assert( paoPoints != NULL ); memset( paoPoints + nPointCount, 0, sizeof(OGRRawPoint) * (nNewPointCount - nPointCount) ); if( getCoordinateDimension() == 3 ) { padfZ = (double *) OGRRealloc( padfZ, sizeof(double)*nNewPointCount ); memset( padfZ + nPointCount, 0, sizeof(double) * (nNewPointCount - nPointCount) ); } } nPointCount = nNewPointCount; }
static ERL_NIF_TERM gdal_nif_get_srs_wkt_of(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { int epsg_code; if (enif_get_int(env, argv[0], &epsg_code)) { char* wkt = get_wkt_of(epsg_code); ERL_NIF_TERM res = enif_make_tuple2(env, ATOM_OK, enif_make_string(env, wkt ,ERL_NIF_LATIN1)); OGRFree(wkt); return res; } else { return enif_make_badarg(env); } }
void OGRCurveCollection::empty(OGRGeometry* poGeom) { if( papoCurves != NULL ) { for( int i = 0; i < nCurveCount; i++ ) { delete papoCurves[i]; } OGRFree( papoCurves ); } nCurveCount = 0; papoCurves = NULL; if( poGeom ) poGeom->setCoordinateDimension(2); }
static dErr JakoGDALDatasetCreateMem(OGRSpatialReferenceH ref,const double geo[6],dInt n,dInt nlines,GDALDataType dtype,GDALDatasetH *dset,void *bandmem) { char *wkt; GDALDriverH memdriver; CPLErr cplerr; OGRErr oerr; dErr err; dFunctionBegin; oerr = OSRExportToWkt(ref,&wkt);dOGRCHK(oerr); memdriver = GDALGetDriverByName("MEM"); *dset = GDALCreate(memdriver,"MEM:::",n,nlines,0,dtype,NULL); cplerr = GDALSetProjection(*dset,wkt);dCPLCHK(cplerr); cplerr = GDALSetGeoTransform(*dset,(double*)geo);dCPLCHK(cplerr); /* const-incorrect interface */ OGRFree(wkt); if (bandmem) {err = JakoGDALMemAddBand(*dset,GDT_Float64,&bandmem);dCHK(err);} dFunctionReturn(0); }
std::string Polygon::json(double precision) const { std::ostringstream prec; prec << precision; char **papszOptions = NULL; papszOptions = CSLSetNameValue(papszOptions, "COORDINATE_PRECISION", prec.str().c_str() ); std::string w(wkt()); gdal::SpatialRef srs(m_srs.getWKT(pdal::SpatialReference::eCompoundOK)); gdal::Geometry g(w, srs); char* json = OGR_G_ExportToJsonEx(g.get(), papszOptions); std::string output(json); OGRFree(json); return output; }
void object::test<3>() { ensure("SRS UTM handle is NULL", NULL != srs_utm_); ensure("SRS LL handle is NULL", NULL != srs_ll_); err_ = OSRSetUTM(srs_utm_, 11, TRUE); ensure_equals("Can't set UTM zone", err_, OGRERR_NONE); err_ = OSRSetWellKnownGeogCS(srs_utm_, "WGS84"); ensure_equals("Can't set GeogCS", err_, OGRERR_NONE); err_ = OSRSetWellKnownGeogCS(srs_ll_, "WGS84"); ensure_equals("Can't set GeogCS", err_, OGRERR_NONE); ct_ = OCTNewCoordinateTransformation(srs_ll_, srs_utm_); ensure("PROJ.4 missing, transforms not available", NULL != ct_); const char* wkt = "POINT(-117.5 32.0)"; OGRGeometryH geom = NULL; err_ = OGR_G_CreateFromWkt((char**) &wkt, NULL, &geom); ensure_equals("Can't import geometry from WKT", OGRERR_NONE, err_); ensure("Can't create geometry", NULL != geom); err_ = OGR_G_Transform(geom, ct_); ensure_equals("OGR_G_Transform() failed", err_, OGRERR_NONE); OGRSpatialReferenceH srs = NULL; srs = OGR_G_GetSpatialReference(geom); char* wktSrs = NULL; err_ = OSRExportToPrettyWkt(srs, &wktSrs, FALSE); ensure("Exported SRS to WKT is NULL", NULL != wktSrs); std::string pretty(wktSrs); ensure_equals("SRS output is incorrect", pretty.substr(0, 6), std::string("PROJCS")); OGRFree(wktSrs); OGR_G_DestroyGeometry(geom); }
std::string AlbersConEqArea::wkt() { OGRSpatialReference sr; int epsg = DATUM2EPSG[datum()]; char **wkt = 0; std::string output = ""; OGRErr err; sr.SetProjCS("Albers Conic Equal Area"); if (epsg != -1) { sr.importFromEPSG(epsg); sr.SetACEA(param(2), param(3), param(5), param(4), param(6), param(7)); err = sr.exportToPrettyWkt(wkt); } else { return output; } if (err == OGRERR_NONE) { output = *wkt; OGRFree(wkt); } return output; }
OGRErr OGRMultiPoint::importFromWkt( char ** ppszInput ) { char szToken[OGR_WKT_TOKEN_MAX]; const char *pszInput = *ppszInput; int iGeom; OGRErr eErr = OGRERR_NONE; /* -------------------------------------------------------------------- */ /* Clear existing Geoms. */ /* -------------------------------------------------------------------- */ empty(); /* -------------------------------------------------------------------- */ /* Read and verify the type keyword, and ensure it matches the */ /* actual type of this container. */ /* -------------------------------------------------------------------- */ pszInput = OGRWktReadToken( pszInput, szToken ); if( !EQUAL(szToken,getGeometryName()) ) return OGRERR_CORRUPT_DATA; /* -------------------------------------------------------------------- */ /* Skip past first bracket for checking purposes, but don't */ /* alter pszInput. */ /* -------------------------------------------------------------------- */ const char *pszPreScan = pszInput; // skip white space. while( *pszPreScan == ' ' || *pszPreScan == '\t' ) pszPreScan++; // Skip outer bracket. if( *pszPreScan != '(' ) return OGRERR_CORRUPT_DATA; pszPreScan++; /* -------------------------------------------------------------------- */ /* If the next token is EMPTY, then verify that we have proper */ /* EMPTY format will a trailing closing bracket. */ /* -------------------------------------------------------------------- */ OGRWktReadToken( pszPreScan, szToken ); if( EQUAL(szToken,"EMPTY") ) { pszInput = OGRWktReadToken( pszPreScan, szToken ); pszInput = OGRWktReadToken( pszInput, szToken ); *ppszInput = (char *) pszInput; if( !EQUAL(szToken,")") ) return OGRERR_CORRUPT_DATA; else return OGRERR_NONE; } /* -------------------------------------------------------------------- */ /* Check for inner bracket indicating the improper bracketed */ /* format which we still want to support. */ /* -------------------------------------------------------------------- */ // skip white space. while( *pszPreScan == ' ' || *pszPreScan == '\t' ) pszPreScan++; // Do we have an inner bracket? if( *pszPreScan == '(' ) return importFromWkt_Bracketed( ppszInput ); /* -------------------------------------------------------------------- */ /* Read the point list which should consist of exactly one point. */ /* -------------------------------------------------------------------- */ int nMaxPoint = 0; int nPointCount = 0; OGRRawPoint *paoPoints = NULL; double *padfZ = NULL; pszInput = OGRWktReadPoints( pszInput, &paoPoints, &padfZ, &nMaxPoint, &nPointCount ); if( pszInput == NULL ) return OGRERR_CORRUPT_DATA; /* -------------------------------------------------------------------- */ /* Transform raw points into point objects. */ /* -------------------------------------------------------------------- */ for( iGeom = 0; iGeom < nPointCount && eErr == OGRERR_NONE; iGeom++ ) { OGRGeometry *poGeom; if( padfZ ) poGeom = new OGRPoint( paoPoints[iGeom].x, paoPoints[iGeom].y, padfZ[iGeom] ); else poGeom = new OGRPoint( paoPoints[iGeom].x, paoPoints[iGeom].y ); eErr = addGeometryDirectly( poGeom ); } OGRFree( paoPoints ); if( padfZ ) OGRFree( padfZ ); if( eErr != OGRERR_NONE ) return eErr; *ppszInput = (char *) pszInput; return OGRERR_NONE; }
void QgsGrassNewMapset::setGrassProjection() { QgsDebugMsg( "entered." ); setError( mProjErrorLabel, "" ); QString proj4 = mProjectionSelector->selectedProj4String(); // Not defined if ( mNoProjRadioButton->isChecked() ) { mCellHead.proj = PROJECTION_XY; mCellHead.zone = 0; mProjInfo = 0; mProjUnits = 0; button( QWizard::NextButton )->setEnabled( true ); return; } // Define projection if ( !proj4.isEmpty() ) { QgsDebugMsg( QString( "proj4 = %1" ).arg( proj4.toLocal8Bit().constData() ) ); OGRSpatialReferenceH hCRS = NULL; hCRS = OSRNewSpatialReference( NULL ); int errcode; const char *oldlocale = setlocale( LC_NUMERIC, NULL ); setlocale( LC_NUMERIC, "C" ); errcode = OSRImportFromProj4( hCRS, proj4.toUtf8() ); setlocale( LC_NUMERIC, oldlocale ); if ( errcode != OGRERR_NONE ) { QgsDebugMsg( QString( "OGR can't parse PROJ.4-style parameter string:\n%1\nOGR Error code was %2" ).arg( proj4 ).arg( errcode ) ); mCellHead.proj = PROJECTION_XY; mCellHead.zone = 0; mProjInfo = 0; mProjUnits = 0; } else { char *wkt = NULL; QgsDebugMsg( QString( "OSRIsGeographic = %1" ).arg( OSRIsGeographic( hCRS ) ) ); QgsDebugMsg( QString( "OSRIsProjected = %1" ).arg( OSRIsProjected( hCRS ) ) ); if (( errcode = OSRExportToWkt( hCRS, &wkt ) ) != OGRERR_NONE ) { QgsDebugMsg( QString( "OGR can't get Wkt-style parameter string\nOGR Error code was %1" ).arg( errcode ) ); } else { QgsDebugMsg( QString( "wkt = %1" ).arg( wkt ) ); } // Note: GPJ_osr_to_grass() defaults in PROJECTION_XY if projection // cannot be set // There was a bug in GRASS, it is present in 6.0.x line int ret = GPJ_wkt_to_grass( &mCellHead, &mProjInfo, &mProjUnits, wkt, 0 ); // Note: It seems that GPJ_osr_to_grass()returns always 1, // -> test if mProjInfo was set Q_UNUSED( ret ); QgsDebugMsg( QString( "ret = %1" ).arg( ret ) ); QgsDebugMsg( QString( "mProjInfo = %1" ).arg( QString::number(( qulonglong )mProjInfo, 16 ).toLocal8Bit().constData() ) ); OGRFree( wkt ); } if ( !mProjInfo || !mProjUnits ) { setError( mProjErrorLabel, tr( "Selected projection is not supported by GRASS!" ) ); } } else // Nothing selected { mCellHead.proj = PROJECTION_XY; mCellHead.zone = 0; mProjInfo = 0; mProjUnits = 0; } button( QWizard::NextButton )->setEnabled( mProjInfo && mProjUnits ); }
OGRErr OGRPGDumpLayer::CreateFeatureViaInsert( OGRFeature *poFeature ) { CPLString osCommand; int i = 0; int bNeedComma = FALSE; OGRErr eErr = OGRERR_FAILURE; int bEmptyInsert = FALSE; if( NULL == poFeature ) { CPLError( CE_Failure, CPLE_AppDefined, "NULL pointer to OGRFeature passed to CreateFeatureViaInsert()." ); return eErr; } /* -------------------------------------------------------------------- */ /* Form the INSERT command. */ /* -------------------------------------------------------------------- */ osCommand.Printf( "INSERT INTO %s (", pszSqlTableName ); for(i = 0; i < poFeatureDefn->GetGeomFieldCount(); i++ ) { OGRGeometry *poGeom = poFeature->GetGeomFieldRef(i); if( poGeom != NULL ) { if( bNeedComma ) osCommand += ", "; OGRGeomFieldDefn* poGFldDefn = poFeature->GetGeomFieldDefnRef(i); osCommand = osCommand + OGRPGDumpEscapeColumnName(poGFldDefn->GetNameRef()) + " "; bNeedComma = TRUE; } } if( poFeature->GetFID() != OGRNullFID && pszFIDColumn != NULL ) { if( bNeedComma ) osCommand += ", "; osCommand = osCommand + OGRPGDumpEscapeColumnName(pszFIDColumn) + " "; bNeedComma = TRUE; } for( i = 0; i < poFeatureDefn->GetFieldCount(); i++ ) { if( !poFeature->IsFieldSet( i ) ) continue; if( !bNeedComma ) bNeedComma = TRUE; else osCommand += ", "; osCommand = osCommand + OGRPGDumpEscapeColumnName(poFeatureDefn->GetFieldDefn(i)->GetNameRef()); } if (!bNeedComma) bEmptyInsert = TRUE; osCommand += ") VALUES ("; /* Set the geometry */ bNeedComma = FALSE; for(i = 0; i < poFeatureDefn->GetGeomFieldCount(); i++ ) { OGRGeometry *poGeom = poFeature->GetGeomFieldRef(i); if( poGeom != NULL ) { char *pszWKT = NULL; OGRPGDumpGeomFieldDefn* poGFldDefn = (OGRPGDumpGeomFieldDefn*) poFeature->GetGeomFieldDefnRef(i); poGeom->closeRings(); poGeom->setCoordinateDimension( poGFldDefn->nCoordDimension ); if( bNeedComma ) osCommand += ", "; if( bWriteAsHex ) { char* pszHex = OGRGeometryToHexEWKB( poGeom, poGFldDefn->nSRSId ); osCommand += "'"; if (pszHex) osCommand += pszHex; osCommand += "'"; CPLFree(pszHex); } else { poGeom->exportToWkt( &pszWKT ); if( pszWKT != NULL ) { osCommand += CPLString().Printf( "GeomFromEWKT('SRID=%d;%s'::TEXT) ", poGFldDefn->nSRSId, pszWKT ); OGRFree( pszWKT ); } else osCommand += "''"; } bNeedComma = TRUE; } } /* Set the FID */ if( poFeature->GetFID() != OGRNullFID && pszFIDColumn != NULL ) { if( bNeedComma ) osCommand += ", "; osCommand += CPLString().Printf( "%ld ", poFeature->GetFID() ); bNeedComma = TRUE; } for( i = 0; i < poFeatureDefn->GetFieldCount(); i++ ) { if( !poFeature->IsFieldSet( i ) ) continue; if( bNeedComma ) osCommand += ", "; else bNeedComma = TRUE; AppendFieldValue(osCommand, poFeature, i); } osCommand += ")"; if (bEmptyInsert) osCommand.Printf( "INSERT INTO %s DEFAULT VALUES", pszSqlTableName ); /* -------------------------------------------------------------------- */ /* Execute the insert. */ /* -------------------------------------------------------------------- */ poDS->Log(osCommand); return OGRERR_NONE; }
OGRErr OGRGeometryCollection::importFromWkb( unsigned char * pabyData, int nSize ) { OGRwkbByteOrder eByteOrder; int nDataOffset; if( nSize < 9 && nSize != -1 ) return OGRERR_NOT_ENOUGH_DATA; /* -------------------------------------------------------------------- */ /* Get the byte order byte. */ /* -------------------------------------------------------------------- */ eByteOrder = DB2_V72_FIX_BYTE_ORDER((OGRwkbByteOrder) *pabyData); CPLAssert( eByteOrder == wkbXDR || eByteOrder == wkbNDR ); /* -------------------------------------------------------------------- */ /* Get the geometry feature type. For now we assume that */ /* geometry type is between 0 and 255 so we only have to fetch */ /* one byte. */ /* -------------------------------------------------------------------- */ #ifdef DEBUG OGRwkbGeometryType eGeometryType; if( eByteOrder == wkbNDR ) { eGeometryType = (OGRwkbGeometryType) pabyData[1]; } else { eGeometryType = (OGRwkbGeometryType) pabyData[4]; } CPLAssert( eGeometryType == wkbGeometryCollection || eGeometryType == wkbMultiPolygon || eGeometryType == wkbMultiLineString || eGeometryType == wkbMultiPoint ); #endif /* -------------------------------------------------------------------- */ /* Do we already have some existing geometry objects? */ /* -------------------------------------------------------------------- */ if( nGeomCount != 0 ) { for( int iGeom = 0; iGeom < nGeomCount; iGeom++ ) delete papoGeoms[iGeom]; OGRFree( papoGeoms ); papoGeoms = NULL; } /* -------------------------------------------------------------------- */ /* Get the geometry count. */ /* -------------------------------------------------------------------- */ memcpy( &nGeomCount, pabyData + 5, 4 ); if( OGR_SWAP( eByteOrder ) ) nGeomCount = CPL_SWAP32(nGeomCount); papoGeoms = (OGRGeometry **) OGRMalloc(sizeof(void*) * nGeomCount); nDataOffset = 9; if( nSize != -1 ) nSize -= nDataOffset; nCoordinateDimension = 0; // unknown /* -------------------------------------------------------------------- */ /* Get the Geoms. */ /* -------------------------------------------------------------------- */ for( int iGeom = 0; iGeom < nGeomCount; iGeom++ ) { OGRErr eErr; eErr = OGRGeometryFactory:: createFromWkb( pabyData + nDataOffset, NULL, papoGeoms + iGeom, nSize ); if( eErr != OGRERR_NONE ) { nGeomCount = iGeom; return eErr; } if( nSize != -1 ) nSize -= papoGeoms[iGeom]->WkbSize(); nDataOffset += papoGeoms[iGeom]->WkbSize(); } return OGRERR_NONE; }