Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticket #5357: New OGR_G_SetPointCount and OGR_G_SetPoints functions in API C #28

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions gdal/ogr/ogr_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,38 @@ int OGR_G_GetPointCount( OGRGeometryH hGeom )
}
}

/************************************************************************/
/* OGR_G_SetPointCount() */
/************************************************************************/
/**
* \brief Set number of points in a geometry.
*
* This method primary exists to preset the number of points in a linestring
* geometry before setPoint() is used to assign them to avoid reallocating
* the array larger with each call to addPoint().
*
* @param nNewPointCount the new number of points for geometry.
*/

void OGR_G_SetPointCount( OGRGeometryH hGeom, int nNewPointCount )

{
VALIDATE_POINTER0( hGeom, "OGR_G_SetPointCount" );

switch( wkbFlatten(((OGRGeometry *) hGeom)->getGeometryType()) )
{
case wkbLineString:
{
OGRLineString *poLine = (OGRLineString *) hGeom;
poLine->setNumPoints( nNewPointCount );
break;
}
default:
CPLError(CE_Failure, CPLE_NotSupported, "Incompatible geometry for operation");
break;
}
}

/************************************************************************/
/* OGR_G_GetX() */
/************************************************************************/
Expand Down Expand Up @@ -329,6 +361,73 @@ void OGR_G_GetPoint( OGRGeometryH hGeom, int i,
}
}

/************************************************************************/
/* OGR_G_SetPoint() */
/************************************************************************/
/**
* \brief Assign all points in a point or a line string geometry.
*
* This method clear any existing points assigned to this geometry,
* and assigns a whole new set.
*
* @param hGeom handle to the geometry to set the coordinates.
* @param nPointsIn number of points being passed in padfX and padfY.
* @param padfX list of X coordinates of points being assigned.
* @param nXStride the number of bytes between 2 elements of pabyX.
* @param padfY list of Y coordinates of points being assigned.
* @param nYStride the number of bytes between 2 elements of pabyY.
* @param padfZ list of Z coordinates of points being assigned (defaults to NULL for 2D objects).
* @param nZStride the number of bytes between 2 elements of pabyZ.
*/

void CPL_DLL OGR_G_SetPoints( OGRGeometryH hGeom, int nPointsIn,
void* pabyX, int nXStride,
void* pabyY, int nYStride,
void* pabyZ, int nZStride )

{
VALIDATE_POINTER0( hGeom, "OGR_G_SetPoints" );

switch( wkbFlatten(((OGRGeometry *) hGeom)->getGeometryType()) )
{
case wkbPoint:
{
((OGRPoint *) hGeom)->setX( pabyX ? *( (double *)pabyX ) : 0.0 );
((OGRPoint *) hGeom)->setY( pabyY ? *( (double *)pabyY ) : 0.0 );
((OGRPoint *) hGeom)->setZ( pabyZ ? *( (double *)pabyZ ) : 0.0 );
break;
}
case wkbLineString:
{
OGRLineString* poLine = (OGRLineString *) hGeom;

if( nXStride == 0 && nYStride == 0 && nZStride == 0 )
{
poLine->setPoints( nPointsIn, (double *)pabyX, (double *)pabyY, (double *)pabyZ );
}
else
{
double x, y, z;
x = y = z = 0;
poLine->setNumPoints( nPointsIn );

for (int i = 0; i < nPointsIn; ++i)
{
if( pabyX ) x = *(double*)((char*)pabyX + i * nXStride);
if( pabyY ) y = *(double*)((char*)pabyY + i * nYStride);
if( pabyZ ) z = *(double*)((char*)pabyZ + i * nZStride);

poLine->setPoint( i, x, y, z );
}
}
break;
}
default:
CPLError(CE_Failure, CPLE_NotSupported, "Incompatible geometry for operation");
break;
}
}

/************************************************************************/
/* OGR_G_SetPoint() */
/************************************************************************/
Expand Down
5 changes: 5 additions & 0 deletions gdal/ogr/ogr_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,17 @@ double CPL_DLL OGR_G_GetY( OGRGeometryH, int );
double CPL_DLL OGR_G_GetZ( OGRGeometryH, int );
void CPL_DLL OGR_G_GetPoint( OGRGeometryH, int iPoint,
double *, double *, double * );
void CPL_DLL OGR_G_SetPointCount( OGRGeometryH hGeom, int nNewPointCount );
void CPL_DLL OGR_G_SetPoint( OGRGeometryH, int iPoint,
double, double, double );
void CPL_DLL OGR_G_SetPoint_2D( OGRGeometryH, int iPoint,
double, double );
void CPL_DLL OGR_G_AddPoint( OGRGeometryH, double, double, double );
void CPL_DLL OGR_G_AddPoint_2D( OGRGeometryH, double, double );
void CPL_DLL OGR_G_SetPoints( OGRGeometryH hGeom, int nPointsIn,
void* pabyX, int nXStride,
void* pabyY, int nYStride,
void* pabyZ, int nZStride );

/* Methods for getting/setting rings and members collections */

Expand Down