Changeset 11992
- Timestamp:
- 08/29/07 10:07:30 (1 year ago)
- Files:
-
- trunk/gdal/ogr/ogrsf_frmts/ili/ili1reader.cpp (modified) (17 diffs)
- trunk/gdal/ogr/ogrsf_frmts/ili/ili1readerp.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/gdal/ogr/ogrsf_frmts/ili/ili1reader.cpp
r11344 r11992 86 86 if( fpItf == NULL ) 87 87 { 88 CPLError( CE_Failure, CPLE_OpenFailed, 89 "Failed to open ILI file `%s'.", 88 CPLError( CE_Failure, CPLE_OpenFailed, 89 "Failed to open ILI file `%s'.", 90 90 pszFilename ); 91 91 … … 181 181 iom_init(); 182 182 183 // set error listener to a iom provided one, that just 183 // set error listener to a iom provided one, that just 184 184 // dumps all errors to stderr 185 185 iom_seterrlistener(iom_stderrlistener); … … 270 270 const char *topic = NULL; 271 271 int ret = TRUE; 272 272 273 273 while (ret && (tokens = ReadParseLine())) 274 274 { … … 277 277 { 278 278 //read description 279 do 279 do 280 280 { 281 281 pszLine = CPLReadLine( fpItf ); … … 287 287 { 288 288 //read model 289 do 289 do 290 290 { 291 291 pszLine = CPLReadLine( fpItf ); … … 338 338 CPLDebug( "OGR_ILI", "Unexpected token: %s", firsttok ); 339 339 } 340 340 341 341 CSLDestroy(tokens); 342 342 } … … 366 366 } 367 367 368 OGRMultiPolygon* ILI1Reader::Polygonize( OGRGeometryCollection* poLines )368 OGRMultiPolygon* ILI1Reader::Polygonize( OGRGeometryCollection* poLines, bool fix_crossing_lines ) 369 369 { 370 370 OGRMultiPolygon *poPolygon = new OGRMultiPolygon(); 371 372 if (poLines->getNumGeometries() == 0) return poPolygon; 371 373 372 374 #if defined(POLYGONIZE_AREAS) 373 375 GEOSGeom *ahInGeoms = NULL; 374 376 int i = 0; 375 376 ahInGeoms = (GEOSGeom *) CPLCalloc(sizeof(void*),poLines->getNumGeometries()); 377 for( i = 0; i < poLines->getNumGeometries(); i++ ) 378 ahInGeoms[i] = poLines->getGeometryRef(i)->exportToGEOS(); 379 380 381 GEOSGeom hResultGeom = GEOSPolygonize( ahInGeoms, 382 poLines->getNumGeometries() ); 383 384 for( i = 0; i < poLines->getNumGeometries(); i++ ) 377 OGRGeometryCollection *poNoncrossingLines = poLines; 378 GEOSGeom hResultGeom = NULL; 379 OGRGeometry *poMP = NULL; 380 381 if (fix_crossing_lines) 382 { 383 CPLDebug( "OGR_ILI", "Fixing crossing lines"); 384 poNoncrossingLines = (OGRGeometryCollection*)poLines->Union(poLines->getGeometryRef(0)); 385 CPLDebug( "OGR_ILI", "Fixed lines: %d", poNoncrossingLines->getNumGeometries()-poLines->getNumGeometries()); 386 } 387 388 ahInGeoms = (GEOSGeom *) CPLCalloc(sizeof(void*),poNoncrossingLines->getNumGeometries()); 389 for( i = 0; i < poNoncrossingLines->getNumGeometries(); i++ ) 390 ahInGeoms[i] = poNoncrossingLines->getGeometryRef(i)->exportToGEOS(); 391 392 hResultGeom = GEOSPolygonize( ahInGeoms, 393 poNoncrossingLines->getNumGeometries() ); 394 395 for( i = 0; i < poNoncrossingLines->getNumGeometries(); i++ ) 385 396 GEOSGeom_destroy( ahInGeoms[i] ); 386 397 CPLFree( ahInGeoms ); 398 if (poNoncrossingLines != poLines) delete poNoncrossingLines; 387 399 388 400 if( hResultGeom == NULL ) 389 401 return NULL; 390 402 391 OGRGeometry *poMP = OGRGeometryFactory::createFromGEOS( hResultGeom );392 403 poMP = OGRGeometryFactory::createFromGEOS( hResultGeom ); 404 393 405 GEOSGeom_destroy( hResultGeom ); 394 406 … … 417 429 CPLDebug( "OGR_ILI", "Polygonizing layer %s with %d multilines", poAreaLayer->GetLayerDefn()->GetName(), gc->getNumGeometries()); 418 430 OGRMultiPolygon* polys = Polygonize( gc ); 431 if (polys->getNumGeometries() != poAreaLayer->GetFeatureCount()) 432 { 433 delete polys; 434 polys = Polygonize( gc, true ); //try again with crossing line fix 435 } 436 delete gc; 419 437 420 438 //associate polygon feature with data row according to centroid … … 481 499 482 500 int ILI1Reader::ReadTable() { 483 501 484 502 char **tokens = NULL; 485 503 const char *firsttok = NULL; … … 531 549 } 532 550 } 533 551 534 552 int fieldno = 0; 535 553 for (fIndex=1; fIndex<CSLCount(tokens) && fieldno < featureDef->GetFieldCount(); fIndex++, fieldno++) … … 592 610 CPLDebug( "OGR_ILI", "Unexpected token: %s", firsttok ); 593 611 } 594 612 595 613 CSLDestroy(tokens); 596 614 fpos = VSIFTell(fpItf); 597 615 } 598 616 599 617 return ret; 600 618 } 601 619 602 620 void ILI1Reader::ReadGeom(char **stgeom, OGRwkbGeometryType eType, OGRFeature *feature) { 603 621 604 622 char **tokens = NULL; 605 623 const char *firsttok = NULL; … … 697 715 CPLDebug( "OGR_ILI", "Unexpected token: %s", firsttok ); 698 716 } 699 717 700 718 CSLDestroy(tokens); 701 719 } … … 711 729 papoLayers = (OGRILI1Layer **) 712 730 CPLRealloc( papoLayers, sizeof(void*) * ++nLayers ); 713 731 714 732 papoLayers[nLayers-1] = poNewLayer; 715 733 } … … 728 746 papoAreaLineLayers = (OGRILI1Layer **) 729 747 CPLRealloc( papoAreaLineLayers, sizeof(void*) * nAreaLayers ); 730 748 731 749 papoAreaLayers[nAreaLayers-1] = poAreaLayer; 732 750 papoAreaLineLayers[nAreaLayers-1] = poLineLayer; … … 746 764 papoSurfacePolyLayers = (OGRILI1Layer **) 747 765 CPLRealloc( papoSurfacePolyLayers, sizeof(void*) * nSurfaceLayers ); 748 766 749 767 papoSurfaceLayers[nSurfaceLayers-1] = poDataLayer; 750 768 papoSurfacePolyLayers[nSurfaceLayers-1] = poPolyLayer; … … 801 819 if( fpItf == NULL ) 802 820 return( NULL ); 803 821 804 822 pszLine = CPLReadLine( fpItf ); 805 823 if( pszLine == NULL ) 806 824 return( NULL ); 807 825 808 826 if (strlen(pszLine) == 0) return NULL; 809 827 810 828 tokens = CSLTokenizeString2( pszLine, " ", CSLT_PRESERVEESCAPES ); 811 829 token = tokens[CSLCount(tokens)-1]; 812 830 813 831 //Append CONT lines 814 832 while (strlen(pszLine) && EQUALN(token, "\\", 2)) … … 817 835 CPLFree(tokens[CSLCount(tokens)-1]); 818 836 tokens[CSLCount(tokens)-1] = NULL; 819 837 820 838 pszLine = CPLReadLine( fpItf ); 821 839 conttok = CSLTokenizeString2( pszLine, " ", CSLT_PRESERVEESCAPES ); 822 840 if (!conttok || !EQUAL(conttok[0], "CONT")) break; 823 841 824 842 //append 825 843 tokens = CSLInsertStrings(tokens, -1, &conttok[1]); 826 844 token = tokens[CSLCount(tokens)-1]; 827 845 828 846 CSLDestroy(conttok); 829 847 } trunk/gdal/ogr/ogrsf_frmts/ili/ili1readerp.h
r11343 r11992 15 15 * and/or sell copies of the Software, and to permit persons to whom the 16 16 * Software is furnished to do so, subject to the following conditions: 17 * 17 * 18 18 * The above copyright notice and this permission notice shall be included 19 19 * in all copies or substantial portions of the Software. 20 * 20 * 21 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, … … 24 24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 27 * DEALINGS IN THE SOFTWARE. 28 28 ****************************************************************************/ … … 44 44 45 45 class ILI1Reader : public IILI1Reader 46 { 46 { 47 47 private: 48 48 FILE *fpItf; … … 74 74 void AddSurfaceLayer( OGRILI1Layer * poDataLayer, OGRILI1Layer * poPolyLayer ); 75 75 int AddIliGeom(OGRFeature *feature, int iField, long fpos); 76 OGRMultiPolygon* Polygonize( OGRGeometryCollection* poLines );76 OGRMultiPolygon* Polygonize( OGRGeometryCollection* poLines, bool fix_crossing_lines = false ); 77 77 void PolygonizeAreaLayers(); 78 78 void JoinSurfaceLayers();
