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; }
OGRErr OGRLineString::importFromWkt( char ** ppszInput ) { char szToken[OGR_WKT_TOKEN_MAX]; const char *pszInput = *ppszInput; if( paoPoints != NULL ) { nPointCount = 0; CPLFree( paoPoints ); paoPoints = NULL; CPLFree( padfZ ); padfZ = NULL; } /* -------------------------------------------------------------------- */ /* Read and verify the ``LINESTRING'' keyword token. */ /* -------------------------------------------------------------------- */ pszInput = OGRWktReadToken( pszInput, szToken ); if( !EQUAL(szToken,getGeometryName()) ) return OGRERR_CORRUPT_DATA; /* -------------------------------------------------------------------- */ /* Read the point list which should consist of exactly one point. */ /* -------------------------------------------------------------------- */ int nMaxPoint = 0; nPointCount = 0; pszInput = OGRWktReadPoints( pszInput, &paoPoints, &padfZ, &nMaxPoint, &nPointCount ); if( pszInput == NULL ) return OGRERR_CORRUPT_DATA; *ppszInput = (char *) pszInput; return OGRERR_NONE; }
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; }
OGRErr OGRPoint::importFromWkt( char ** ppszInput ) { char szToken[OGR_WKT_TOKEN_MAX]; const char *pszInput = *ppszInput; /* -------------------------------------------------------------------- */ /* Read and verify the ``POINT'' keyword token. */ /* -------------------------------------------------------------------- */ pszInput = OGRWktReadToken( pszInput, szToken ); if( !EQUAL(szToken,"POINT") ) return OGRERR_CORRUPT_DATA; /* -------------------------------------------------------------------- */ /* Check for EMPTY ... but treat like a point at 0,0. */ /* -------------------------------------------------------------------- */ const char *pszPreScan; pszPreScan = OGRWktReadToken( pszInput, szToken ); if( EQUAL(szToken,"EMPTY") ) { *ppszInput = (char *) pszInput; empty(); return OGRERR_NONE; } if( !EQUAL(szToken,"(") ) return OGRERR_CORRUPT_DATA; pszPreScan = OGRWktReadToken( pszPreScan, szToken ); if( EQUAL(szToken,"EMPTY") ) { pszInput = OGRWktReadToken( pszPreScan, szToken ); if( !EQUAL(szToken,")") ) return OGRERR_CORRUPT_DATA; else { *ppszInput = (char *) pszInput; empty(); return OGRERR_NONE; } } /* -------------------------------------------------------------------- */ /* Read the point list which should consist of exactly one point. */ /* -------------------------------------------------------------------- */ OGRRawPoint *poPoints = NULL; double *padfZ = NULL; int nMaxPoint = 0, nPoints = 0; pszInput = OGRWktReadPoints( pszInput, &poPoints, &padfZ, &nMaxPoint, &nPoints ); if( pszInput == NULL || nPoints != 1 ) return OGRERR_CORRUPT_DATA; x = poPoints[0].x; y = poPoints[0].y; CPLFree( poPoints ); if( padfZ != NULL ) { z = padfZ[0]; nCoordDimension = 3; CPLFree( padfZ ); } else nCoordDimension = 2; *ppszInput = (char *) pszInput; return OGRERR_NONE; }
OGRErr OGRMultiLineString::importFromWkt( char ** ppszInput ) { char szToken[OGR_WKT_TOKEN_MAX]; const char *pszInput = *ppszInput; OGRErr eErr; /* -------------------------------------------------------------------- */ /* Clear existing rings. */ /* -------------------------------------------------------------------- */ empty(); /* -------------------------------------------------------------------- */ /* Read and verify the ``MULTILINESTRING'' keyword token. */ /* -------------------------------------------------------------------- */ pszInput = OGRWktReadToken( pszInput, szToken ); if( !EQUAL(szToken,getGeometryName()) ) return OGRERR_CORRUPT_DATA; /* -------------------------------------------------------------------- */ /* The next character should be a ( indicating the start of the */ /* list of linestrings. */ /* -------------------------------------------------------------------- */ pszInput = OGRWktReadToken( pszInput, szToken ); if( EQUAL(szToken,"EMPTY") ) { *ppszInput = (char *) pszInput; return OGRERR_NONE; } if( szToken[0] != '(' ) return OGRERR_CORRUPT_DATA; /* -------------------------------------------------------------------- */ /* If the next token is EMPTY, then verify that we have proper */ /* EMPTY format will a trailing closing bracket. */ /* -------------------------------------------------------------------- */ OGRWktReadToken( pszInput, szToken ); if( EQUAL(szToken,"EMPTY") ) { pszInput = OGRWktReadToken( pszInput, szToken ); pszInput = OGRWktReadToken( pszInput, szToken ); *ppszInput = (char *) pszInput; if( !EQUAL(szToken,")") ) return OGRERR_CORRUPT_DATA; else return OGRERR_NONE; } /* ==================================================================== */ /* Read each line in turn. Note that we try to reuse the same */ /* point list buffer from ring to ring to cut down on */ /* allocate/deallocate overhead. */ /* ==================================================================== */ OGRRawPoint *paoPoints = NULL; int nMaxPoints = 0; double *padfZ = NULL; do { int nPoints = 0; /* -------------------------------------------------------------------- */ /* Read points for one line from input. */ /* -------------------------------------------------------------------- */ pszInput = OGRWktReadPoints( pszInput, &paoPoints, &padfZ, &nMaxPoints, &nPoints ); if( pszInput == NULL ) { eErr = OGRERR_CORRUPT_DATA; break; } /* -------------------------------------------------------------------- */ /* Create the new line, and add to collection. */ /* -------------------------------------------------------------------- */ OGRLineString *poLine; poLine = new OGRLineString(); poLine->setPoints( nPoints, paoPoints, padfZ ); eErr = addGeometryDirectly( poLine ); /* -------------------------------------------------------------------- */ /* Read the delimeter following the ring. */ /* -------------------------------------------------------------------- */ pszInput = OGRWktReadToken( pszInput, szToken ); } while( szToken[0] == ',' && eErr == OGRERR_NONE ); /* -------------------------------------------------------------------- */ /* freak if we don't get a closing bracket. */ /* -------------------------------------------------------------------- */ CPLFree( paoPoints ); CPLFree( padfZ ); if( eErr != OGRERR_NONE ) return eErr; if( szToken[0] != ')' ) return OGRERR_CORRUPT_DATA; *ppszInput = (char *) pszInput; return OGRERR_NONE; }
OGRErr OGRPoint::importFromWkt( char ** ppszInput ) { int bHasZ = FALSE, bHasM = FALSE; OGRErr eErr = importPreambuleFromWkt(ppszInput, &bHasZ, &bHasM); if( eErr >= 0 ) { if( eErr == OGRERR_NONE ) /* only the case for an EMPTY case */ nCoordDimension = (bHasZ) ? -3 : -2; return eErr; } const char *pszInput = *ppszInput; /* -------------------------------------------------------------------- */ /* Read the point list which should consist of exactly one point. */ /* -------------------------------------------------------------------- */ OGRRawPoint *poPoints = NULL; double *padfZ = NULL; int nMaxPoint = 0, nPoints = 0; pszInput = OGRWktReadPoints( pszInput, &poPoints, &padfZ, &nMaxPoint, &nPoints ); if( pszInput == NULL || nPoints != 1 ) { CPLFree( poPoints ); CPLFree( padfZ ); return OGRERR_CORRUPT_DATA; } x = poPoints[0].x; y = poPoints[0].y; CPLFree( poPoints ); if( padfZ != NULL ) { /* If there's a 3rd value, and it is not a POINT M, */ /* then assume it is the Z */ if ((!(bHasM && !bHasZ))) { z = padfZ[0]; nCoordDimension = 3; } else nCoordDimension = 2; CPLFree( padfZ ); } else if ( bHasZ ) { /* In theory we should have a z coordinate for POINT Z */ /* oh well, let be tolerant */ nCoordDimension = 3; } else nCoordDimension = 2; *ppszInput = (char *) pszInput; return OGRERR_NONE; }
OGRErr OGRPolygon::importFromWkt( char ** ppszInput ) { char szToken[OGR_WKT_TOKEN_MAX]; const char *pszInput = *ppszInput; int iRing; /* -------------------------------------------------------------------- */ /* Clear existing rings. */ /* -------------------------------------------------------------------- */ if( nRingCount > 0 ) { for( iRing = 0; iRing < nRingCount; iRing++ ) delete papoRings[iRing]; nRingCount = 0; CPLFree( papoRings ); } /* -------------------------------------------------------------------- */ /* Read and verify the ``POLYGON'' keyword token. */ /* -------------------------------------------------------------------- */ pszInput = OGRWktReadToken( pszInput, szToken ); if( !EQUAL(szToken,"POLYGON") ) return OGRERR_CORRUPT_DATA; /* -------------------------------------------------------------------- */ /* The next character should be a ( indicating the start of the */ /* list of rings. */ /* -------------------------------------------------------------------- */ pszInput = OGRWktReadToken( pszInput, szToken ); if( szToken[0] != '(' ) return OGRERR_CORRUPT_DATA; /* ==================================================================== */ /* Read each ring in turn. Note that we try to reuse the same */ /* point list buffer from ring to ring to cut down on */ /* allocate/deallocate overhead. */ /* ==================================================================== */ OGRRawPoint *paoPoints = NULL; int nMaxPoints = 0, nMaxRings = 0; double *padfZ = NULL; do { int nPoints = 0; /* -------------------------------------------------------------------- */ /* Read points for one ring from input. */ /* -------------------------------------------------------------------- */ pszInput = OGRWktReadPoints( pszInput, &paoPoints, &padfZ, &nMaxPoints, &nPoints ); if( pszInput == NULL ) { CPLFree( paoPoints ); return OGRERR_CORRUPT_DATA; } /* -------------------------------------------------------------------- */ /* Do we need to grow the ring array? */ /* -------------------------------------------------------------------- */ if( nRingCount == nMaxRings ) { nMaxRings = nMaxRings * 2 + 1; papoRings = (OGRLinearRing **) CPLRealloc(papoRings, nMaxRings * sizeof(OGRLinearRing*)); } /* -------------------------------------------------------------------- */ /* Create the new ring, and assign to ring list. */ /* -------------------------------------------------------------------- */ papoRings[nRingCount] = new OGRLinearRing(); papoRings[nRingCount]->setPoints( nPoints, paoPoints, padfZ ); nRingCount++; /* -------------------------------------------------------------------- */ /* Read the delimeter following the ring. */ /* -------------------------------------------------------------------- */ pszInput = OGRWktReadToken( pszInput, szToken ); } while( szToken[0] == ',' ); /* -------------------------------------------------------------------- */ /* freak if we don't get a closing bracket. */ /* -------------------------------------------------------------------- */ CPLFree( paoPoints ); CPLFree( padfZ ); if( szToken[0] != ')' ) return OGRERR_CORRUPT_DATA; *ppszInput = (char *) pszInput; return OGRERR_NONE; }
OGRErr OGRPolygon::importFromWkt( char ** ppszInput ) { char szToken[OGR_WKT_TOKEN_MAX]; const char *pszInput = *ppszInput; int iRing; /* -------------------------------------------------------------------- */ /* Clear existing rings. */ /* -------------------------------------------------------------------- */ if( nRingCount > 0 ) { for( iRing = 0; iRing < nRingCount; iRing++ ) delete papoRings[iRing]; nRingCount = 0; CPLFree( papoRings ); } /* -------------------------------------------------------------------- */ /* Read and verify the ``POLYGON'' keyword token. */ /* -------------------------------------------------------------------- */ pszInput = OGRWktReadToken( pszInput, szToken ); if( !EQUAL(szToken,"POLYGON") ) return OGRERR_CORRUPT_DATA; /* -------------------------------------------------------------------- */ /* Check for EMPTY ... */ /* -------------------------------------------------------------------- */ const char *pszPreScan; int bHasZ = FALSE, bHasM = FALSE; pszPreScan = OGRWktReadToken( pszInput, szToken ); if( EQUAL(szToken,"EMPTY") ) { *ppszInput = (char *) pszPreScan; empty(); return OGRERR_NONE; } /* -------------------------------------------------------------------- */ /* Check for Z, M or ZM. Will ignore the Measure */ /* -------------------------------------------------------------------- */ else if( EQUAL(szToken,"Z") ) { bHasZ = TRUE; } else if( EQUAL(szToken,"M") ) { bHasM = TRUE; } else if( EQUAL(szToken,"ZM") ) { bHasZ = TRUE; bHasM = TRUE; } if (bHasZ || bHasM) { pszInput = pszPreScan; pszPreScan = OGRWktReadToken( pszInput, szToken ); if( EQUAL(szToken,"EMPTY") ) { *ppszInput = (char *) pszPreScan; empty(); /* FIXME?: In theory we should store the dimension and M presence */ /* if we want to allow round-trip with ExportToWKT v1.2 */ return OGRERR_NONE; } } if( !EQUAL(szToken,"(") ) return OGRERR_CORRUPT_DATA; if ( !bHasZ && !bHasM ) { /* Test for old-style POLYGON(EMPTY) */ pszPreScan = OGRWktReadToken( pszPreScan, szToken ); if( EQUAL(szToken,"EMPTY") ) { pszPreScan = OGRWktReadToken( pszPreScan, szToken ); if( EQUAL(szToken,",") ) { /* This is OK according to SFSQL SPEC. */ } else if( !EQUAL(szToken,")") ) return OGRERR_CORRUPT_DATA; else { *ppszInput = (char *) pszPreScan; empty(); return OGRERR_NONE; } } } /* Skip first '(' */ pszInput = OGRWktReadToken( pszInput, szToken ); /* ==================================================================== */ /* Read each ring in turn. Note that we try to reuse the same */ /* point list buffer from ring to ring to cut down on */ /* allocate/deallocate overhead. */ /* ==================================================================== */ OGRRawPoint *paoPoints = NULL; int nMaxPoints = 0, nMaxRings = 0; double *padfZ = NULL; nCoordDimension = 2; do { int nPoints = 0; const char* pszNext = OGRWktReadToken( pszInput, szToken ); if (EQUAL(szToken,"EMPTY")) { /* -------------------------------------------------------------------- */ /* Do we need to grow the ring array? */ /* -------------------------------------------------------------------- */ if( nRingCount == nMaxRings ) { nMaxRings = nMaxRings * 2 + 1; papoRings = (OGRLinearRing **) CPLRealloc(papoRings, nMaxRings * sizeof(OGRLinearRing*)); } papoRings[nRingCount] = new OGRLinearRing(); nRingCount++; pszInput = OGRWktReadToken( pszNext, szToken ); if ( !EQUAL(szToken, ",") ) break; continue; } /* -------------------------------------------------------------------- */ /* Read points for one ring from input. */ /* -------------------------------------------------------------------- */ pszInput = OGRWktReadPoints( pszInput, &paoPoints, &padfZ, &nMaxPoints, &nPoints ); if( pszInput == NULL || nPoints == 0 ) { CPLFree( paoPoints ); return OGRERR_CORRUPT_DATA; } /* -------------------------------------------------------------------- */ /* Do we need to grow the ring array? */ /* -------------------------------------------------------------------- */ if( nRingCount == nMaxRings ) { nMaxRings = nMaxRings * 2 + 1; papoRings = (OGRLinearRing **) CPLRealloc(papoRings, nMaxRings * sizeof(OGRLinearRing*)); } /* -------------------------------------------------------------------- */ /* Create the new ring, and assign to ring list. */ /* -------------------------------------------------------------------- */ papoRings[nRingCount] = new OGRLinearRing(); /* Ignore Z array when we have a POLYGON M */ if (bHasM && !bHasZ) papoRings[nRingCount]->setPoints( nPoints, paoPoints, NULL ); else papoRings[nRingCount]->setPoints( nPoints, paoPoints, padfZ ); nRingCount++; if( padfZ && !(bHasM && !bHasZ) ) nCoordDimension = 3; /* -------------------------------------------------------------------- */ /* Read the delimeter following the ring. */ /* -------------------------------------------------------------------- */ pszInput = OGRWktReadToken( pszInput, szToken ); } while( szToken[0] == ',' ); /* -------------------------------------------------------------------- */ /* freak if we don't get a closing bracket. */ /* -------------------------------------------------------------------- */ CPLFree( paoPoints ); CPLFree( padfZ ); if( szToken[0] != ')' ) return OGRERR_CORRUPT_DATA; *ppszInput = (char *) pszInput; return OGRERR_NONE; }
OGRErr OGRPoint::importFromWkt( char ** ppszInput ) { char szToken[OGR_WKT_TOKEN_MAX]; const char *pszInput = *ppszInput; /* -------------------------------------------------------------------- */ /* Read and verify the ``POINT'' keyword token. */ /* -------------------------------------------------------------------- */ pszInput = OGRWktReadToken( pszInput, szToken ); if( !EQUAL(szToken,"POINT") ) return OGRERR_CORRUPT_DATA; /* -------------------------------------------------------------------- */ /* Check for EMPTY ... but treat like a point at 0,0. */ /* -------------------------------------------------------------------- */ const char *pszPreScan; int bHasZ = FALSE, bHasM = FALSE; pszPreScan = OGRWktReadToken( pszInput, szToken ); if( EQUAL(szToken,"EMPTY") ) { *ppszInput = (char *) pszPreScan; empty(); return OGRERR_NONE; } /* -------------------------------------------------------------------- */ /* Check for Z, M or ZM. Will ignore the Measure */ /* -------------------------------------------------------------------- */ else if( EQUAL(szToken,"Z") ) { bHasZ = TRUE; } else if( EQUAL(szToken,"M") ) { bHasM = TRUE; } else if( EQUAL(szToken,"ZM") ) { bHasZ = TRUE; bHasM = TRUE; } if (bHasZ || bHasM) { pszInput = pszPreScan; pszPreScan = OGRWktReadToken( pszInput, szToken ); if( EQUAL(szToken,"EMPTY") ) { *ppszInput = (char *) pszPreScan; empty(); /* FIXME?: In theory we should store the dimension and M presence */ /* if we want to allow round-trip with ExportToWKT v1.2 */ return OGRERR_NONE; } } if( !EQUAL(szToken,"(") ) return OGRERR_CORRUPT_DATA; if ( !bHasZ && !bHasM ) { /* Test for old-style POINT(EMPTY) */ pszPreScan = OGRWktReadToken( pszPreScan, szToken ); if( EQUAL(szToken,"EMPTY") ) { pszInput = OGRWktReadToken( pszPreScan, szToken ); if( !EQUAL(szToken,")") ) return OGRERR_CORRUPT_DATA; else { *ppszInput = (char *) pszInput; empty(); return OGRERR_NONE; } } } /* -------------------------------------------------------------------- */ /* Read the point list which should consist of exactly one point. */ /* -------------------------------------------------------------------- */ OGRRawPoint *poPoints = NULL; double *padfZ = NULL; int nMaxPoint = 0, nPoints = 0; pszInput = OGRWktReadPoints( pszInput, &poPoints, &padfZ, &nMaxPoint, &nPoints ); if( pszInput == NULL || nPoints != 1 ) { CPLFree( poPoints ); CPLFree( padfZ ); return OGRERR_CORRUPT_DATA; } x = poPoints[0].x; y = poPoints[0].y; CPLFree( poPoints ); if( padfZ != NULL ) { /* If there's a 3rd value, and it is not a POINT M, */ /* then assume it is the Z */ if ((!(bHasM && !bHasZ))) { z = padfZ[0]; nCoordDimension = 3; } else nCoordDimension = 2; CPLFree( padfZ ); } else if ( bHasZ ) { /* In theory we should have a z coordinate for POINT Z */ /* oh well, let be tolerant */ nCoordDimension = 3; } else nCoordDimension = 2; *ppszInput = (char *) pszInput; return OGRERR_NONE; }
OGRErr OGRLineString::importFromWkt( char ** ppszInput ) { char szToken[OGR_WKT_TOKEN_MAX]; const char *pszInput = *ppszInput; if( paoPoints != NULL ) { nPointCount = 0; CPLFree( paoPoints ); paoPoints = NULL; CPLFree( padfZ ); padfZ = NULL; } /* -------------------------------------------------------------------- */ /* Read and verify the ``LINESTRING'' keyword token. */ /* -------------------------------------------------------------------- */ pszInput = OGRWktReadToken( pszInput, szToken ); if( !EQUAL(szToken,getGeometryName()) ) return OGRERR_CORRUPT_DATA; /* -------------------------------------------------------------------- */ /* Check for EMPTY ... but treat like a point at 0,0. */ /* -------------------------------------------------------------------- */ const char *pszPreScan; pszPreScan = OGRWktReadToken( pszInput, szToken ); if( !EQUAL(szToken,"(") ) return OGRERR_CORRUPT_DATA; pszPreScan = OGRWktReadToken( pszPreScan, szToken ); if( EQUAL(szToken,"EMPTY") ) { pszPreScan = OGRWktReadToken( pszPreScan, szToken ); *ppszInput = (char *) pszPreScan; if( !EQUAL(szToken,")") ) return OGRERR_CORRUPT_DATA; else return OGRERR_NONE; } /* -------------------------------------------------------------------- */ /* Read the point list. */ /* -------------------------------------------------------------------- */ int nMaxPoint = 0; nPointCount = 0; pszInput = OGRWktReadPoints( pszInput, &paoPoints, &padfZ, &nMaxPoint, &nPointCount ); if( pszInput == NULL ) return OGRERR_CORRUPT_DATA; *ppszInput = (char *) pszInput; return OGRERR_NONE; }
OGRErr OGRMultiPoint::importFromWkt_Bracketed( char ** ppszInput, int bHasM, int bHasZ ) { char szToken[OGR_WKT_TOKEN_MAX]; const char *pszInput = *ppszInput; OGRErr eErr = OGRERR_NONE; /* -------------------------------------------------------------------- */ /* Skip MULTIPOINT keyword. */ /* -------------------------------------------------------------------- */ pszInput = OGRWktReadToken( pszInput, szToken ); if (bHasZ || bHasM) { /* Skip Z, M or ZM */ 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 )) != NULL && (EQUAL(szToken,"(") || EQUAL(szToken,",")) ) { OGRGeometry *poGeom; const char* pszNext = OGRWktReadToken( pszInput, szToken ); if (EQUAL(szToken,"EMPTY")) { poGeom = new OGRPoint(0,0); poGeom->empty(); eErr = addGeometryDirectly( poGeom ); if( eErr != OGRERR_NONE ) return eErr; pszInput = pszNext; continue; } pszInput = OGRWktReadPoints( pszInput, &paoPoints, &padfZ, &nMaxPoint, &nPointCount ); if( pszInput == NULL || nPointCount != 1 ) { OGRFree( paoPoints ); OGRFree( padfZ ); return OGRERR_CORRUPT_DATA; } /* Ignore Z array when we have a MULTIPOINT M */ if( padfZ && !(bHasM && !bHasZ)) 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; }
OGRErr OGRMultiPoint::importFromWkt( char ** ppszInput ) { const char *pszInputBefore = *ppszInput; int bHasZ = FALSE, bHasM = FALSE; OGRErr eErr = importPreambuleFromWkt(ppszInput, &bHasZ, &bHasM); if( eErr >= 0 ) return eErr; char szToken[OGR_WKT_TOKEN_MAX]; const char *pszInput = *ppszInput; int iGeom; eErr = OGRERR_NONE; const char* pszPreScan = OGRWktReadToken( pszInput, szToken ); OGRWktReadToken( pszPreScan, szToken ); // Do we have an inner bracket? if (EQUAL(szToken,"(") || EQUAL(szToken, "EMPTY") ) { *ppszInput = (char*) pszInputBefore; return importFromWkt_Bracketed( ppszInput, bHasM, bHasZ ); } if (bHasZ || bHasM) { return OGRERR_CORRUPT_DATA; } /* -------------------------------------------------------------------- */ /* 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 ) { OGRFree( paoPoints ); OGRFree( padfZ ); 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; }