Re: [gdal-dev] create 25D MultiPolygon how to
legeochen wrote: Hi All I try to create some multipolygons with OGR. After creating them, but when I want view them in arcscene, it just make arcscene crash! Then I tried osgviewer with ESRI Shapefile, I was warned: ESRIShape loader: .dbf file containe different record number that .shp file. .dbf record skipped. Inspect your shapefile with ogrinfo as well as with Shapelib's shpdump and dbfdump. Check if .dbf contains exactly the same number of records as .shp file Actually, only one feature in the dataset had been readed out. Then, I tried osgviewer with ogr, got warnings like this: Warning something wrong with a polygon in a multi polygon. No idea what's osgviewer and what its errors mean. for(Roadway::RoadWayArray::iterator itrw = _roadwayArr.begin(); itrw != _roadwayArr.end();itrw++) ++itrw; if you care about performance. { OGRFeature *poFeature; OGRMultiPolygon multiPoly; poFeature = OGRFeature::CreateFeature(poLayer-GetLayerDefn()); Roadway::Triangle_list tris = (*itrw)-getTrianglelist(); No idea what Triangle and Roadway is, I assume it's your own geometry type. for(Triangle_list::const_iterator ittri = tris.begin();ittri != tris.end();ittri++) ++ittri; { OGRPolygon polygon; OGRLinearRing poRing; poRing.addPoint((*ittri).a().x(),(*ittri).a().y(),(*ittri).a().z()); poRing.addPoint((*ittri).b().x(),(*ittri).b().y(),(*ittri).b().z()); poRing.addPoint((*ittri).c().x(),(*ittri).c().y(),(*ittri).c().z()); poRing.addPoint((*ittri).a().x(),(*ittri).a().y(),(*ittri).a().z()); Assure that TRUE == poRing.get_IsClosed(); polygon.addRing(poRing); multiPoly.addGeometry(polygon); } poFeature-SetGeometry(multiPoly); if( poLayer-CreateFeature( poFeature ) != OGRERR_NONE ) { printf( Failed to create feature in shapefile.\n ); return false; } OGRFeature::DestroyFeature( poFeature ); } OGRDataSource::DestroyDataSource( poDS ); Any help is appreciated!! I'd suggest you to translate your Roadway/Triangle it to OGRPolygon and OGRMultiPolygon (what you actually have done) and then dump it to OGC Well-Known-Text (WKT). Then, try to validate these geometries with PostGIS using ST_GeometryFromText and ST_IsValid and friends. See chapter 4 and 6 of PostGIS manual. PostGIS (or GEOS) is good for geometries validation. Best regards, -- Mateusz Loskot, http://mateusz.loskot.net Charter Member of OSGeo, http://osgeo.org ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] create 25D MultiPolygon how to
Mateusz Loskot wrote: for(Roadway::RoadWayArray::iterator itrw = _roadwayArr.begin(); itrw != _roadwayArr.end();itrw++) ++itrw; if you care about performance. Mateusz, Just curious. Why should that impact on performance? Joaquim Luis ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] create 25D MultiPolygon how to
Joaquim Luis wrote: Mateusz Loskot wrote: for(Roadway::RoadWayArray::iterator itrw = _roadwayArr.begin(); itrw != _roadwayArr.end();itrw++) ++itrw; if you care about performance. Mateusz, Just curious. Why should that impact on performance? The itrw here is most likely an iterator of type of user's class. The pointer arithmetic does work here only in terms of semantic, but not in terms of implementation. Meaning, both versions do the same - advance to next position: int* p = ...; // or any ordinary type p++; iterator it = ...; it++; However, the realization is completely different. Here is example of how pre- and post-increment operator is usually declared in a class: struct T { T operator++(); // pre- T operator++(int); // post- }; The pre-increment operator returns reference to the object itself (return *this;) The post-increment returns a temporary copy of the object. There are important side-effects of returning copy: 1. it is constructed - copy-construction - constructor called 2. it is returned by value - copy-construction - constructor called Here is example of iterator and operator++ implementation: http://liblas.org/browser/trunk/include/liblas/iterator.hpp?rev813#L108 Object construction is considered in C++ as an expansive operation, next to dynamic storage allocation. If post-increment/decrement operator is used against pointers and integers, temporary object is also created, but as they are native types no constructor call is involved. People report different measurements on Usenet groups. Numbers vary but can easily hit 50 % of performance increase if you stick to use of pre-increment/decrement operator for class types. Best regards, -- Mateusz Loskot, http://mateusz.loskot.net Charter Member of OSGeo, http://osgeo.org ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] create 25D MultiPolygon how to
Joaquim Luis wrote: Thankx I'll keep this in mind if I ever one day start practicing C++ For the time being, only good old C. You are welcome. Simply, best thing is to always use pre-increment, regardless if working with pointers, integers or iterators. Then there is no need to remember about copy-construction issue when you switch to objects. Best regards, -- Mateusz Loskot, http://mateusz.loskot.net Charter Member of OSGeo, http://osgeo.org ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] create 25D MultiPolygon how to
Wow: I have tried your suggestion. but it won't work. It seems the shp file create by ogr is a little different from which generated with shplib. reading shp file ceated by ogr with shplib gives me warning like the dbf. containe different record than shp. Actually, only the first geometry can be read out. 2009/3/3 legeochen legeoc...@gmail.com Wow: Tanks for your suggestion! Yeaph! That maybe where the rub is. I will try it out soon. cheers! 2009/3/3 wow 27949...@qq.com Hi, Your code looks like that you didn't create any field for the feature. At least create one field would ensure success. Like this: OGRFieldDefn oField( Name, OFTString ); oField.SetWidth(32); if( pLayer-CreateField( oField ) != OGRERR_NONE ) { printf( Creating Name field failed.\n ); exit( 1 ); } Xuexia Chen -- To the world you're little, but to a person, maybe you're the world. -- Original -- *From: * legeochenlegeoc...@gmail.com; *Date: * Fri, Feb 27, 2009 09:47 PM *To: * Gdal-Devgdal-dev@lists.osgeo.org; *Subject: * [gdal-dev] create 25D MultiPolygon how to Hi All I try to create some multipolygons?with OGR.?After creating them, but when I want view them in arcscene, it just make arcscene crash! Then I tried osgviewer with ESRI Shapefile, I was warned: ESRIShape loader: .dbf file containe different record number that .shp file. .dbf record skipped. Actually, only one feature in the dataset had been readed out. Then, I tried osgviewer with ogr, got warnings like this: Warning something wrong with a polygon in a multi polygon. And, the result is not quite as expected! Here is?my code: ?const char* pszDriverName = ESRI Shapefile; ?OGRSFDriver *poDriver; ?OGRRegisterAll(); ??? poDriver = OGRSFDriverRegistrar::GetRegistrar()-GetDriverByName( ??? pszDriverName ); ??? if( poDriver == NULL ) ??? { ??? printf( %s driver not available.\n, pszDriverName ); ??? return false; ??? } ?OGRDataSource *poDS; ?poDS = poDriver-Open(shpfile,TRUE); ?if(poDS == NULL) ??poDS = poDriver-CreateDataSource(shpfile,NULL); ?if(poDS == NULL) ?{ ??printf(Creation of output file failed.\n); ??return false; ?} ?OGRLayer* poLayer = poDS-GetLayerByName (layername); ?if(poLayer == NULL) ?{ ??if( !poDS-TestCapability( ODsCCreateLayer ) ) ??? { ??? fprintf( stderr, ? Layer Roadway not found, and CreateLayer not supported by driver. ); ??? return FALSE; ??? } ??CPLErrorReset(); ??poLayer = poDS-CreateLayer(layername,NULL,wkbMultiPolygon25D,NULL); ??if(poLayer == NULL) ??{ ???printf( Layer creation failed.\n ); ???return false; ??} ?} ?for(Roadway::RoadWayArray::iterator itrw = _roadwayArr.begin(); itrw != _roadwayArr.end();itrw++) ?{ ??OGRFeature *poFeature; ?? ??OGRMultiPolygon multiPoly; ??poFeature = OGRFeature::CreateFeature(poLayer-GetLayerDefn()); ??Roadway::Triangle_list tris = (*itrw)-getTrianglelist(); ??for(Triangle_list::const_iterator ittri = tris.begin();ittri != tris.end();ittri++) ??{ ???OGRPolygon polygon; ???OGRLinearRing poRing; ???poRing.addPoint((*ittri).a().x(),(*ittri).a().y(),(*ittri).a().z()); ???poRing.addPoint((*ittri).b().x(),(*ittri).b().y(),(*ittri).b().z()); ???poRing.addPoint((*ittri).c().x(),(*ittri).c().y(),(*ittri).c().z()); ???poRing.addPoint((*ittri).a().x(),(*ittri).a().y(),(*ittri).a().z()); ??? ???polygon.addRing(poRing); ???multiPoly.addGeometry(polygon); ??? ??} ??poFeature-SetGeometry(multiPoly); ??if( poLayer-CreateFeature( poFeature ) != OGRERR_NONE ) ??{ ???printf( Failed to create feature in shapefile.\n );?? ???return false; ??} ??OGRFeature::DestroyFeature( poFeature ); ?} ?OGRDataSource::DestroyDataSource( poDS ); Any help is appreciated!!? ? ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] create 25D MultiPolygon how to
Wow: Tanks for your suggestion! Yeaph! That maybe where the rub is. I will try it out soon. cheers! 2009/3/3 wow 27949...@qq.com Hi, Your code looks like that you didn't create any field for the feature. At least create one field would ensure success. Like this: OGRFieldDefn oField( Name, OFTString ); oField.SetWidth(32); if( pLayer-CreateField( oField ) != OGRERR_NONE ) { printf( Creating Name field failed.\n ); exit( 1 ); } Xuexia Chen -- To the world you're little, but to a person, maybe you're the world. -- Original -- *From: * legeochenlegeoc...@gmail.com; *Date: * Fri, Feb 27, 2009 09:47 PM *To: * Gdal-Devgdal-dev@lists.osgeo.org; *Subject: * [gdal-dev] create 25D MultiPolygon how to Hi All I try to create some multipolygons?with OGR.?After creating them, but when I want view them in arcscene, it just make arcscene crash! Then I tried osgviewer with ESRI Shapefile, I was warned: ESRIShape loader: .dbf file containe different record number that .shp file. .dbf record skipped. Actually, only one feature in the dataset had been readed out. Then, I tried osgviewer with ogr, got warnings like this: Warning something wrong with a polygon in a multi polygon. And, the result is not quite as expected! Here is?my code: ?const char* pszDriverName = ESRI Shapefile; ?OGRSFDriver *poDriver; ?OGRRegisterAll(); ??? poDriver = OGRSFDriverRegistrar::GetRegistrar()-GetDriverByName( ??? pszDriverName ); ??? if( poDriver == NULL ) ??? { ??? printf( %s driver not available.\n, pszDriverName ); ??? return false; ??? } ?OGRDataSource *poDS; ?poDS = poDriver-Open(shpfile,TRUE); ?if(poDS == NULL) ??poDS = poDriver-CreateDataSource(shpfile,NULL); ?if(poDS == NULL) ?{ ??printf(Creation of output file failed.\n); ??return false; ?} ?OGRLayer* poLayer = poDS-GetLayerByName (layername); ?if(poLayer == NULL) ?{ ??if( !poDS-TestCapability( ODsCCreateLayer ) ) ??? { ??? fprintf( stderr, ? Layer Roadway not found, and CreateLayer not supported by driver. ); ??? return FALSE; ??? } ??CPLErrorReset(); ??poLayer = poDS-CreateLayer(layername,NULL,wkbMultiPolygon25D,NULL); ??if(poLayer == NULL) ??{ ???printf( Layer creation failed.\n ); ???return false; ??} ?} ?for(Roadway::RoadWayArray::iterator itrw = _roadwayArr.begin(); itrw != _roadwayArr.end();itrw++) ?{ ??OGRFeature *poFeature; ?? ??OGRMultiPolygon multiPoly; ??poFeature = OGRFeature::CreateFeature(poLayer-GetLayerDefn()); ??Roadway::Triangle_list tris = (*itrw)-getTrianglelist(); ??for(Triangle_list::const_iterator ittri = tris.begin();ittri != tris.end();ittri++) ??{ ???OGRPolygon polygon; ???OGRLinearRing poRing; ???poRing.addPoint((*ittri).a().x(),(*ittri).a().y(),(*ittri).a().z()); ???poRing.addPoint((*ittri).b().x(),(*ittri).b().y(),(*ittri).b().z()); ???poRing.addPoint((*ittri).c().x(),(*ittri).c().y(),(*ittri).c().z()); ???poRing.addPoint((*ittri).a().x(),(*ittri).a().y(),(*ittri).a().z()); ??? ???polygon.addRing(poRing); ???multiPoly.addGeometry(polygon); ??? ??} ??poFeature-SetGeometry(multiPoly); ??if( poLayer-CreateFeature( poFeature ) != OGRERR_NONE ) ??{ ???printf( Failed to create feature in shapefile.\n );?? ???return false; ??} ??OGRFeature::DestroyFeature( poFeature ); ?} ?OGRDataSource::DestroyDataSource( poDS ); Any help is appreciated!!? ? ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
[gdal-dev] create 25D MultiPolygon how to
Hi All I try to create some multipolygons with OGR. After creating them, but when I want view them in arcscene, it just make arcscene crash! Then I tried osgviewer with ESRI Shapefile, I was warned: ESRIShape loader: .dbf file containe different record number that .shp file. .dbf record skipped. Actually, only one feature in the dataset had been readed out. Then, I tried osgviewer with ogr, got warnings like this: Warning something wrong with a polygon in a multi polygon. And, the result is not quite as expected! Here is my code: const char* pszDriverName = ESRI Shapefile; OGRSFDriver *poDriver; OGRRegisterAll(); poDriver = OGRSFDriverRegistrar::GetRegistrar()-GetDriverByName( pszDriverName ); if( poDriver == NULL ) { printf( %s driver not available.\n, pszDriverName ); return false; } OGRDataSource *poDS; poDS = poDriver-Open(shpfile,TRUE); if(poDS == NULL) poDS = poDriver-CreateDataSource(shpfile,NULL); if(poDS == NULL) { printf(Creation of output file failed.\n); return false; } OGRLayer* poLayer = poDS-GetLayerByName (layername); if(poLayer == NULL) { if( !poDS-TestCapability( ODsCCreateLayer ) ) { fprintf( stderr, Layer Roadway not found, and CreateLayer not supported by driver. ); return FALSE; } CPLErrorReset(); poLayer = poDS-CreateLayer(layername,NULL,wkbMultiPolygon25D,NULL); if(poLayer == NULL) { printf( Layer creation failed.\n ); return false; } } for(Roadway::RoadWayArray::iterator itrw = _roadwayArr.begin(); itrw != _roadwayArr.end();itrw++) { OGRFeature *poFeature; OGRMultiPolygon multiPoly; poFeature = OGRFeature::CreateFeature(poLayer-GetLayerDefn()); Roadway::Triangle_list tris = (*itrw)-getTrianglelist(); for(Triangle_list::const_iterator ittri = tris.begin();ittri != tris.end();ittri++) { OGRPolygon polygon; OGRLinearRing poRing; poRing.addPoint((*ittri).a().x(),(*ittri).a().y(),(*ittri).a().z()); poRing.addPoint((*ittri).b().x(),(*ittri).b().y(),(*ittri).b().z()); poRing.addPoint((*ittri).c().x(),(*ittri).c().y(),(*ittri).c().z()); poRing.addPoint((*ittri).a().x(),(*ittri).a().y(),(*ittri).a().z()); polygon.addRing(poRing); multiPoly.addGeometry(polygon); } poFeature-SetGeometry(multiPoly); if( poLayer-CreateFeature( poFeature ) != OGRERR_NONE ) { printf( Failed to create feature in shapefile.\n ); return false; } OGRFeature::DestroyFeature( poFeature ); } OGRDataSource::DestroyDataSource( poDS ); Any help is appreciated!! ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev