Exemple #1
0
void wxGISSimpleCircleSymbol::Draw(const wxGISGeometry &Geometry, int nLevel)
{
    if (!Geometry.IsOk() || !m_pDisplay)
        return;

    OGRwkbGeometryType eGeomType = wkbFlatten(Geometry.GetType());
    if (eGeomType != wkbMultiPoint)
        return;

    OGREnvelope Env;
    OGRGeometry *pGeom = Geometry;

    OGRMultiPoint* pMPT = (OGRMultiPoint*)pGeom;
    OGRPoint* pCenterPt = (OGRPoint*)pMPT->getGeometryRef(0);
    OGRPoint* pOriginPt = (OGRPoint*)pMPT->getGeometryRef(1);
    double dfRadius = sqrt((pCenterPt->getX() - pOriginPt->getX())*(pCenterPt->getX() - pOriginPt->getX()) + (pCenterPt->getY() - pOriginPt->getY())*(pCenterPt->getY() - pOriginPt->getY()));
    Env.MaxX = pCenterPt->getX() + dfRadius;
    Env.MinX = pCenterPt->getX() - dfRadius;
    Env.MaxY = pCenterPt->getY() + dfRadius;
    Env.MinY = pCenterPt->getY() - dfRadius;

    if (!m_pDisplay->CanDraw(Env))
        return;

    wxCriticalSectionLocker lock(m_pDisplay->GetLock());

    if (!m_pDisplay->CheckDrawAsPoint(Env, m_pLineSymbol->GetWidth()))
    {
        if (!m_pDisplay->DrawCircle(pCenterPt->getX(), pCenterPt->getY(), 0, 0, dfRadius))
        {
            return;
        }

        if (m_Color.Alpha() > 0)
        {
            switch (m_eFillRule)
            {
            case enumGISFillRuleWinding:
                m_pDisplay->SetFillRule(CAIRO_FILL_RULE_WINDING);
                break;
            case enumGISFillRuleOdd:
                m_pDisplay->SetFillRule(CAIRO_FILL_RULE_EVEN_ODD);
                break;
            }
            m_pDisplay->SetColor(m_Color);
            m_pDisplay->FillPreserve();
        }

    }

    m_pLineSymbol->SetStyleToDisplay();

    m_pDisplay->Stroke();
}
Exemple #2
0
OGRBoolean OGRCurvePolygon::Intersects( const OGRGeometry *poOtherGeom ) const

{
    if( !IsEmpty() && poOtherGeom != NULL &&
        wkbFlatten(poOtherGeom->getGeometryType()) == wkbPoint )
    {
        return ContainsPoint((OGRPoint*)poOtherGeom);
    }
    else
        return OGRGeometry::Intersects(poOtherGeom);
}
Exemple #3
0
OGRGeometry*  NASReader::ConvertGeometry(OGRGeometry* poGeom)
{
    //poGeom = OGRGeometryFactory::forceToLineString( poGeom, false );
    if( poGeom != NULL )
    {
        if( wkbFlatten(poGeom->getGeometryType()) == wkbMultiLineString )
        {
            poGeom = OGRGeometryFactory::forceTo(poGeom, wkbLineString);
        }
    }
    return poGeom;
}
Exemple #4
0
mapnik::geometry::geometry<double> ogr_converter::convert_geometry(OGRGeometry* ogr_geom)
{
    // NOTE: wkbFlatten macro in ogr flattens 2.5d types into base 2d type
    switch (wkbFlatten(ogr_geom->getGeometryType()))
    {
    case wkbPoint:
        return convert_point(static_cast<OGRPoint*>(ogr_geom));
        break;
    case wkbMultiPoint:
        return convert_multipoint(static_cast<OGRMultiPoint*>(ogr_geom));
        break;
    case wkbLinearRing:
        return convert_linestring(static_cast<OGRLinearRing*>(ogr_geom));
        break;
    case wkbLineString:
        return convert_linestring(static_cast<OGRLineString*>(ogr_geom));
        break;
    case wkbMultiLineString:
        return convert_multilinestring(static_cast<OGRMultiLineString*>(ogr_geom));
        break;
    case wkbPolygon:
        return convert_polygon(static_cast<OGRPolygon*>(ogr_geom));
        break;
    case wkbMultiPolygon:
        return convert_multipolygon(static_cast<OGRMultiPolygon*>(ogr_geom));
        break;
    case wkbGeometryCollection:
        return convert_collection(static_cast<OGRGeometryCollection*>(ogr_geom));
        break;
    case wkbNone:
    case wkbUnknown:
    default:
        {
            MAPNIK_LOG_WARN(ogr) << "ogr_converter: unknown <ogr> geometry_type="
                                 << wkbFlatten(ogr_geom->getGeometryType());
        }
        return mapnik::geometry::geometry<double>();
        break;
    }
}
OGRErr OGRIngresTableLayer::PrepareNewStyleGeometry(
    OGRGeometry *poGeom, CPLString &osRetGeomText )

{
	OGRErr eErr = OGRERR_NONE;
    osRetGeomText = "";

    if( poGeom == NULL )
        return OGRERR_FAILURE;

/* -------------------------------------------------------------------- */
/*      Point                                                           */
/* -------------------------------------------------------------------- */
    if( wkbFlatten(poGeom->getGeometryType()) == wkbPoint )
    {
        osRetGeomText.Printf( "POINTFROMWKB( ~V )");
    }
/* -------------------------------------------------------------------- */
/*      Linestring                                                      */
/* -------------------------------------------------------------------- */
    else if( wkbFlatten(poGeom->getGeometryType()) == wkbLineString )
    {
        osRetGeomText.Printf("LINEFROMWKB( ~V )");
    }
/* -------------------------------------------------------------------- */
/*      Polygon                                                         */
/* -------------------------------------------------------------------- */
    else if( wkbFlatten(poGeom->getGeometryType()) == wkbPolygon )
    {
        osRetGeomText.Printf("POLYFROMWKB( ~V )");
    }
/* -------------------------------------------------------------------- */
/*      Multipoint                                                      */
/* -------------------------------------------------------------------- */
    else if( wkbFlatten(poGeom->getGeometryType()) == wkbMultiPoint )
    {
        osRetGeomText.Printf("MPOINTFROMWKB( ~V )");
    }
/* -------------------------------------------------------------------- */
/*      Multilinestring                                                 */
/* -------------------------------------------------------------------- */
    else if( wkbFlatten(poGeom->getGeometryType()) == wkbMultiLineString )
    {
    	osRetGeomText.Printf("MLINEFROMWKB( ~V )");
    }
/* -------------------------------------------------------------------- */
/*      Multipolygon                                                    */
/* -------------------------------------------------------------------- */
    else if( wkbFlatten(poGeom->getGeometryType()) == wkbMultiPolygon )
    {
    	osRetGeomText.Printf("MPOLYFROMWKB( ~V )");
    }
    else
    {
        eErr = OGRERR_FAILURE;
    }

    return eErr;
}
QgsOgrFeatureSource::QgsOgrFeatureSource( const QgsOgrProvider* p )
    : mProvider( p )
{
  mFilePath = p->filePath();
  mLayerName = p->layerName();
  mLayerIndex = p->layerIndex();
  mSubsetString = p->mSubsetString;
  mEncoding = p->mEncoding; // no copying - this is a borrowed pointer from Qt
  mFields = p->mAttributeFields;
  mDriverName = p->ogrDriverName;
  mOgrGeometryTypeFilter = wkbFlatten( p->mOgrGeometryTypeFilter );
  QgsOgrConnPool::refS( mFilePath );
}
Exemple #7
0
void OGR_G_GetPoint( OGRGeometryH hGeom, int i, 
                     double *pdfX, double *pdfY, double *pdfZ )

{
    VALIDATE_POINTER0( hGeom, "OGR_G_GetPoint" );

    switch( wkbFlatten(((OGRGeometry *) hGeom)->getGeometryType()) )
    {
      case wkbPoint:
      {
          if( i == 0 )
          {
              *pdfX = ((OGRPoint *)hGeom)->getX();
              *pdfY = ((OGRPoint *)hGeom)->getY();
              if( pdfZ != NULL )
                  *pdfZ = ((OGRPoint *)hGeom)->getZ();
          }
          else
          {
              CPLError(CE_Failure, CPLE_NotSupported, "Only i == 0 is supported");
          }
      }
      break;

      case wkbLineString:
      case wkbCircularString:
      {
          OGRLineString* poLS = (OGRLineString *) hGeom;
          if (i < 0 || i >= poLS->getNumPoints())
          {
              CPLError(CE_Failure, CPLE_NotSupported, "Index out of bounds");
              *pdfX = *pdfY = 0;
              if( pdfZ != NULL )
                  *pdfZ = 0;
          }
          else
          {
            *pdfX = poLS->getX( i );
            *pdfY = poLS->getY( i );
            if( pdfZ != NULL )
                *pdfZ =  poLS->getZ( i );
          }
      }
      break;

      default:
        CPLError(CE_Failure, CPLE_NotSupported, "Incompatible geometry for operation");
        break;
    }
}
void OGRGeometryCollection::closeRings()

{
    for( auto&& poSubGeom: *this )
    {
        if( OGR_GT_IsSubClassOf(
                     wkbFlatten(poSubGeom->getGeometryType()),
                                wkbCurvePolygon ) )
        {
            OGRCurvePolygon *poPoly = poSubGeom->toCurvePolygon();
            poPoly->closeRings();
        }
    }
}
int OGRPolygon::PointOnSurface( OGRPoint *poPoint ) const

{
    if( poPoint == NULL )
        return OGRERR_FAILURE;
 
#ifndef HAVE_GEOS
    return OGRERR_FAILURE;
#else
    GEOSGeom hThisGeosGeom = NULL;
    GEOSGeom hOtherGeosGeom = NULL;
     
    hThisGeosGeom = exportToGEOS();
 
    if( hThisGeosGeom != NULL )
    {
     	hOtherGeosGeom = GEOSPointOnSurface( hThisGeosGeom );
        GEOSGeom_destroy( hThisGeosGeom );

        if( hOtherGeosGeom == NULL )
            return OGRERR_FAILURE;

        OGRGeometry *poInsidePointGeom = (OGRGeometry *) 
            OGRGeometryFactory::createFromGEOS( hOtherGeosGeom );
 
        GEOSGeom_destroy( hOtherGeosGeom );

        if (poInsidePointGeom == NULL)
            return OGRERR_FAILURE;
        if (wkbFlatten(poInsidePointGeom->getGeometryType()) != wkbPoint)
        {
            delete poInsidePointGeom;
            return OGRERR_FAILURE;
        }

        OGRPoint *poInsidePoint = (OGRPoint *) poInsidePointGeom;
 	poPoint->setX( poInsidePoint->getX() );
 	poPoint->setY( poInsidePoint->getY() );
 
        delete poInsidePointGeom;
 
     	return OGRERR_NONE;
    }
    else
    {
     	return OGRERR_FAILURE;
    }
#endif /* HAVE_GEOS */
}
Exemple #10
0
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:
      case wkbCircularString:
      {
        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;
    }
}
Exemple #11
0
void wxGISSimpleMarkerSymbol::Draw(const wxGISGeometry &Geometry, int nLevel)
{
    if(!Geometry.IsOk() ||!m_pDisplay)
        return;

    OGRwkbGeometryType eGeomType = wkbFlatten(Geometry.GetType());
    if(eGeomType != wkbPoint && eGeomType != wkbMultiPoint)
        return;

    OGREnvelope Env = Geometry.GetEnvelope();
    if(!m_pDisplay->CanDraw(Env))
        return;

    OGRGeometry *pGeom = Geometry;

    if(eGeomType == wkbMultiPoint)
    {
		OGRGeometryCollection* pOGRGeometryCollection = (OGRGeometryCollection*)pGeom;
		for(int i = 0; i < pOGRGeometryCollection->getNumGeometries(); ++i)
			Draw(wxGISGeometry(pOGRGeometryCollection->getGeometryRef(i), false));
        return;
    }

    wxCriticalSectionLocker lock(m_pDisplay->GetLock());

    OGRPoint* pPoint = (OGRPoint*)pGeom;
	if(m_dfOutlineSize)
	{
		if(!m_pDisplay->DrawPointFast(pPoint->getX(), pPoint->getY()))
        {
			return;
        }
        m_pDisplay->SetColor(m_OutlineColor);
		m_pDisplay->SetLineWidth( m_dfSize + m_dfOutlineSize + m_dfOutlineSize);
        m_pDisplay->Stroke();
	}

	if(!m_pDisplay->DrawPointFast(pPoint->getX(), pPoint->getY()))
    {
		return;
    }

    m_pDisplay->SetColor(m_Color);
	m_pDisplay->SetLineWidth( m_dfSize );
    m_pDisplay->SetLineCap(CAIRO_LINE_CAP_ROUND);
    m_pDisplay->Stroke();
}
void wxSimpleMarkerSymbol::Draw(OGRGeometry* pGeometry, IDisplay* pwxGISDisplay)
{
	IDisplayTransformation* pDisplayTransformation = pwxGISDisplay->GetDisplayTransformation();
	OGRwkbGeometryType type = wkbFlatten(pGeometry->getGeometryType());
	switch(type)
	{
	case wkbPoint:
		{
			OGRPoint *pPoint = (OGRPoint*)pGeometry;
			OGRRawPoint Point;
			Point.x = pPoint->getX();
			Point.y = pPoint->getY();
			wxPoint* pPoints = pDisplayTransformation->TransformCoordWorld2DC(&Point, 1);
			pwxGISDisplay->SetBrush(m_Brush);
			pwxGISDisplay->SetPen(m_Pen);
			pwxGISDisplay->DrawCircle(pPoints[0].x, pPoints[0].y, m_Size);
			delete[](pPoints);
		}
		break;
	case wkbPolygon:
	case wkbMultiPolygon:
	case wkbLineString:
	case wkbLinearRing:
	case wkbMultiPoint:
	case wkbMultiLineString:
	case wkbGeometryCollection:
		{
			OGREnvelope sEnvelope;
			pGeometry->getEnvelope(&sEnvelope);
			//
			//
			OGRRawPoint Point;
			Point.x = sEnvelope.MinX;
			Point.y = sEnvelope.MinY;
			wxPoint* pPoints = pDisplayTransformation->TransformCoordWorld2DC(&Point, 1);
			pwxGISDisplay->SetBrush(m_Brush);
			pwxGISDisplay->SetPen(m_Pen);
			pwxGISDisplay->DrawPoint(pPoints[0].x, pPoints[0].y);
			delete[](pPoints);
		}
		break;
	case wkbUnknown:
	case wkbNone:
	default:
		break;
	}
}
OGRErr OGRCompoundCurve::addCurveDirectlyInternal( OGRCurve* poCurve,
        double dfToleranceEps,
        int bNeedRealloc )
{
    if( poCurve->getNumPoints() == 1 )
    {
        CPLError(CE_Failure, CPLE_AppDefined, "Invalid curve: not enough points");
        return OGRERR_FAILURE;
    }

    OGRwkbGeometryType eCurveType = wkbFlatten(poCurve->getGeometryType());
    if( EQUAL(poCurve->getGeometryName(), "LINEARRING") )
    {
        CPLError(CE_Failure, CPLE_AppDefined, "Linearring not allowed.");
        return OGRERR_FAILURE;
    }
    else if( eCurveType == wkbCompoundCurve )
    {
        CPLError(CE_Failure, CPLE_AppDefined, "Cannot add a compound curve inside a compound curve");
        return OGRERR_FAILURE;
    }

    if( oCC.nCurveCount > 0 )
    {
        if( oCC.papoCurves[oCC.nCurveCount-1]->IsEmpty() ||
                poCurve->IsEmpty() )
        {
            CPLError(CE_Failure, CPLE_AppDefined, "Non contiguous curves");
            return OGRERR_FAILURE;
        }

        OGRPoint end, start;
        oCC.papoCurves[oCC.nCurveCount-1]->EndPoint(&end);
        poCurve->StartPoint(&start);
        if( fabs(end.getX() - start.getX()) > dfToleranceEps ||
                fabs(end.getY() - start.getY()) > dfToleranceEps ||
                fabs(end.getZ() - start.getZ()) > dfToleranceEps )
        {
            CPLError(CE_Failure, CPLE_AppDefined, "Non contiguous curves");
            return OGRERR_FAILURE;
        }
        ((OGRSimpleCurve*)poCurve)->setPoint(0, &end); /* patch so that it matches exactly */
    }

    return oCC.addCurveDirectly(this, poCurve, bNeedRealloc);
}
Exemple #14
0
OGRwkbGeometryType Geometry::getGeometryType_fixed(OGRGeometry* geom)
{
	//For some reason OGRLinearRing::getGeometryType uses OGRLineString's method...
	//meaning OGRLinearRing::getGeometryType returns wkbLineString

	//http://trac.osgeo.org/gdal/ticket/1755

	OGRwkbGeometryType type =  wkbFlatten(geom->getGeometryType());

	if (type == wkbLineString) {
		if (std::string(geom->getGeometryName()) == "LINEARRING") {
			return wkbLinearRing;
		}
	}

	return type;
}
Exemple #15
0
int OGR_G_GetPointCount( OGRGeometryH hGeom )

{
    VALIDATE_POINTER1( hGeom, "OGR_G_GetPointCount", 0 );

    OGRwkbGeometryType eGType = wkbFlatten(((OGRGeometry *) hGeom)->getGeometryType());
    if( eGType == wkbPoint )
        return 1;
    else if( OGR_GT_IsCurve(eGType) )
        return ((OGRCurve *) hGeom)->getNumPoints();
    else
    {
        // autotest/pymod/ogrtest.py calls this method on any geometry. So keep silent
        //CPLError(CE_Failure, CPLE_NotSupported, "Incompatible geometry for operation");
        return 0;
    }
}
Exemple #16
0
/*!
  \brief Recursively descend to feature and read the part
  
  \param Map pointer to Map_info structure
  \param hGeom OGR geometry
  \param offset given offset
  \param[out] Points container used to store line pointes within
  
  \return feature type
  \return -1 on error
*/
static int get_line_type(const struct Map_info *Map, long FID)
{
    int eType;
    OGRFeatureH hFeat;
    OGRGeometryH hGeom;

    G_debug(4, "get_line_type() fid = %ld", FID);

    hFeat = OGR_L_GetFeature(Map->fInfo.ogr.layer, FID);
    if (hFeat == NULL)
	return -1;

    hGeom = OGR_F_GetGeometryRef(hFeat);
    if (hGeom == NULL)
	return -1;
    
    eType = wkbFlatten(OGR_G_GetGeometryType(hGeom));

    OGR_F_Destroy(hFeat);

    G_debug(4, "OGR Geometry of type: %d", eType);

    switch (eType) {
    case wkbPoint:
    case wkbMultiPoint:
	return GV_POINT;
	break;
	
    case wkbLineString:
    case wkbMultiLineString:
	return GV_LINE;
	break;

    case wkbPolygon:
    case wkbMultiPolygon:
    case wkbGeometryCollection:
	return GV_BOUNDARY;
	break;

    default:
	G_warning(_("OGR feature type %d not supported"), eType);
	break;
    }

    return -1;
}
Exemple #17
0
void wxGISSimpleEllipseSymbol::Draw(const wxGISGeometry &Geometry, int nLevel)
{
    if (!Geometry.IsOk() || !m_pDisplay)
        return;

    OGRwkbGeometryType eGeomType = wkbFlatten(Geometry.GetType());
    if (eGeomType != wkbPolygon)
        return;

    OGREnvelope Env = Geometry.GetEnvelope();
    if (!m_pDisplay->CanDraw(Env))
        return;

    wxCriticalSectionLocker lock(m_pDisplay->GetLock());

    if (!m_pDisplay->CheckDrawAsPoint(Env, m_pLineSymbol->GetWidth()))
    {

        if (!m_pDisplay->DrawEllipse(Env.MinX, Env.MinY, 0, 0, Env.MaxX - Env.MinX, Env.MaxY - Env.MinY))
        {
            return;
        }

        if (m_Color.Alpha() > 0)
        {
            switch (m_eFillRule)
            {
            case enumGISFillRuleWinding:
                m_pDisplay->SetFillRule(CAIRO_FILL_RULE_WINDING);
                break;
            case enumGISFillRuleOdd:
                m_pDisplay->SetFillRule(CAIRO_FILL_RULE_EVEN_ODD);
                break;
            }
            m_pDisplay->SetColor(m_Color);
            m_pDisplay->FillPreserve();
        }

    }

    m_pLineSymbol->SetStyleToDisplay();

    m_pDisplay->Stroke();

}
Exemple #18
0
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;
    }
}
Exemple #19
0
int OGR_G_GetPointCount( OGRGeometryH hGeom )

{
    switch( wkbFlatten(((OGRGeometry *) hGeom)->getGeometryType()) )
    {
      case wkbPoint:
        return 1;

      case wkbLineString:
      {
          OGRLineString *poLine = (OGRLineString *) hGeom;
          return poLine->getNumPoints();
      }

      default:
        return 0;
    }
}
Exemple #20
0
OGRBoolean OGRPoint::Intersects( const OGRGeometry *poOtherGeom ) const

{
    if( !IsEmpty() && poOtherGeom != NULL &&
        wkbFlatten(poOtherGeom->getGeometryType()) == wkbCurvePolygon )
    {
        const OGRCurvePolygon *poCurve =
            dynamic_cast<const OGRCurvePolygon *>(poOtherGeom);
        if( poCurve == NULL )
        {
            CPLError(CE_Fatal, CPLE_AppDefined,
                     "dynamic_cast failed.  Expected OGRCurvePolygon.");
            return FALSE;
        }
        return poCurve->Intersects(this);
    }

    return OGRGeometry::Intersects(poOtherGeom);
}
Exemple #21
0
OGRGeometry* OGRPolygon::getCurveGeometry(const char* const* papszOptions) const
{
    OGRCurvePolygon* poCC = new OGRCurvePolygon();
    poCC->assignSpatialReference( getSpatialReference() );
    bool bHasCurveGeometry = false;
    for( int iRing = 0; iRing < oCC.nCurveCount; iRing++ )
    {
        OGRCurve* poSubGeom = (OGRCurve* )oCC.papoCurves[iRing]->getCurveGeometry(papszOptions);
        if( wkbFlatten(poSubGeom->getGeometryType()) != wkbLineString )
            bHasCurveGeometry = true;
        poCC->addRingDirectly( poSubGeom );
    }
    if( !bHasCurveGeometry )
    {
        delete poCC;
        return clone();
    }
    return poCC;
}
double OGRGeometryCollection::get_Length() const
{
    double dfLength = 0.0;
    for( int iGeom = 0; iGeom < nGeomCount; iGeom++ )
    {
        OGRGeometry* geom = papoGeoms[iGeom];
        OGRwkbGeometryType eType = wkbFlatten(geom->getGeometryType());
        if( OGR_GT_IsCurve(eType) )
        {
            dfLength += ((OGRCurve *) geom)->get_Length();
        }
        else if( OGR_GT_IsSubClassOf(eType, wkbMultiCurve) ||
                eType == wkbGeometryCollection )
        {
            dfLength += ((OGRGeometryCollection *) geom)->get_Length();
        }
    }

    return dfLength;
}
Exemple #23
0
double OGR_G_GetX( OGRGeometryH hGeom, int i )

{
    switch( wkbFlatten(((OGRGeometry *) hGeom)->getGeometryType()) )
    {
      case wkbPoint:
      {
          if( i == 0 )
              return ((OGRPoint *) hGeom)->getX();
          else
              return 0.0;
      }

      case wkbLineString:
        return ((OGRLineString *) hGeom)->getX( i );

      default:
        return 0.0;
    }
}
Exemple #24
0
double OGR_G_Area( OGRGeometryH hGeom )

{
    VALIDATE_POINTER1( hGeom, "OGR_G_Area", 0 );

    double fArea = 0.0;

    switch( wkbFlatten(((OGRGeometry *) hGeom)->getGeometryType()) )
    {
      case wkbPolygon:
        fArea = ((OGRPolygon *) hGeom)->get_Area();
        break;

      case wkbMultiPolygon:
        fArea = ((OGRMultiPolygon *) hGeom)->get_Area();
        break;

      case wkbLinearRing:
      case wkbLineString:
        /* This test below is required to filter out wkbLineString geometries
         * not being of type of wkbLinearRing.
         */
        if( EQUAL( ((OGRGeometry*) hGeom)->getGeometryName(), "LINEARRING" ) )
        {
            fArea = ((OGRLinearRing *) hGeom)->get_Area();
        }
        break;

      case wkbGeometryCollection:
        fArea = ((OGRGeometryCollection *) hGeom)->get_Area();
        break;

      default:
        CPLError( CE_Warning, CPLE_AppDefined,
                  "OGR_G_Area() called against non-surface geometry type." );

        fArea = 0.0;
    }

    return fArea;
}
Exemple #25
0
void wxGISMapView::DrawGeometry(const wxGISGeometry &Geometry, WXGISRGBA stFillColour, WXGISRGBA stLineColour, double dfLineWidth)
{
    wxCHECK_RET(Geometry.IsOk(), wxT("Input geometry is not valid"));

	OGRwkbGeometryType type = wkbFlatten(Geometry.GetType());
	switch(type)
	{
	case wkbPoint:
	case wkbMultiPoint:
	    m_pGISDisplay->SetColor(enumGISDrawStylePoint, stLineColour);
	    m_pGISDisplay->SetColor(enumGISDrawStyleOutline, stLineColour);
	    m_pGISDisplay->SetColor(enumGISDrawStyleFill, stFillColour);
		m_pGISDisplay->SetLineCap(CAIRO_LINE_CAP_ROUND);
		m_pGISDisplay->SetLineWidth(dfLineWidth);
		m_pGISDisplay->SetPointRadius(2.0);
		break;
	case wkbLineString:
	case wkbLinearRing:
	case wkbMultiLineString:
	    m_pGISDisplay->SetColor(enumGISDrawStylePoint, stFillColour);
	    m_pGISDisplay->SetColor(enumGISDrawStyleOutline, stFillColour);
	    m_pGISDisplay->SetColor(enumGISDrawStyleFill, stFillColour);
		m_pGISDisplay->SetLineCap(CAIRO_LINE_CAP_BUTT);
		m_pGISDisplay->SetLineWidth(2.0);
		break;
	case wkbMultiPolygon:
	case wkbPolygon:
	    m_pGISDisplay->SetColor(enumGISDrawStyleOutline, stLineColour);
	    m_pGISDisplay->SetColor(enumGISDrawStyleFill, stFillColour);
		m_pGISDisplay->SetLineCap(CAIRO_LINE_CAP_BUTT);
		m_pGISDisplay->SetLineWidth(dfLineWidth);
		break;
	case wkbGeometryCollection:
		break;
	default:
	case wkbUnknown:
	case wkbNone:
		break;
	}
	m_pGISDisplay->DrawGeometry( Geometry );
}
Exemple #26
0
	/**
	 * 複数のポリゴンから成るオブジェクトを読み込む。
	 * 今の実装は、正確には対応していない。オブジェクトのpartsに順次格納していくだけ。
	 * そのため、アプリケーション側でparts[0]しか使わない場合、まずい。
	 */
	void Shape::readMultiPolygon(OGRMultiPolygon* poMultiPolygon, ShapeObject& shapeObject) {
		int numGeometries = poMultiPolygon->getNumGeometries();
		int partsIndex = 0;
		for (int i = 0; i < numGeometries; ++i) {
			OGRGeometry* geo = poMultiPolygon->getGeometryRef(i);
			if (wkbFlatten(geo->getGeometryType()) == wkbPolygon) {
				OGRPolygon* poPolygon = (OGRPolygon*)geo;

				int nInteriorRings = poPolygon->getNumInteriorRings();
				shapeObject.parts.resize(shapeObject.parts.size() + nInteriorRings + 1);

				OGRLinearRing* ring = poPolygon->getExteriorRing();
				readRing(ring, shapeObject.parts[partsIndex++]);

				for (int j = 0; j < nInteriorRings; ++j) {
					OGRLinearRing* ring = poPolygon->getInteriorRing(j);
					readRing(ring, shapeObject.parts[partsIndex++]);
				}
			}
		}
	}
Exemple #27
0
OGRGeometry *
OGRPolygon::getCurveGeometry( const char* const* papszOptions ) const
{
    OGRCurvePolygon* poCC = new OGRCurvePolygon();
    poCC->assignSpatialReference( getSpatialReference() );
    bool bHasCurveGeometry = false;
    for( auto&& poRing: *this )
    {
        auto poSubGeom =
            poRing->getCurveGeometry(papszOptions);
        if( wkbFlatten(poSubGeom->getGeometryType()) != wkbLineString )
            bHasCurveGeometry = true;
        poCC->addRingDirectly( poSubGeom->toCurve() );
    }
    if( !bHasCurveGeometry )
    {
        delete poCC;
        return clone();
    }
    return poCC;
}
Exemple #28
0
OGRErr OGR_G_RemoveGeometry( OGRGeometryH hGeom, int iGeom, int bDelete )

{
    VALIDATE_POINTER1( hGeom, "OGR_G_RemoveGeometry", 0 );

    OGRwkbGeometryType eType = wkbFlatten(((OGRGeometry *) hGeom)->getGeometryType());
    if( OGR_GT_IsSubClassOf(eType, wkbCurvePolygon) )
    {
        CPLError( CE_Failure, CPLE_AppDefined, 
                "OGR_G_RemoveGeometry() not supported on polygons yet." );
        return OGRERR_UNSUPPORTED_OPERATION;
    }
    else if( OGR_GT_IsSubClassOf(eType, wkbGeometryCollection) )
    {
        return ((OGRGeometryCollection *)hGeom)->removeGeometry( iGeom,bDelete);
    }
    else
    {
        return OGRERR_UNSUPPORTED_OPERATION;
    }
}
double OGRGeometryCollection::get_Length() const
{
    double dfLength = 0.0;
    for( auto&& poSubGeom: *this )
    {
        const OGRwkbGeometryType eType = wkbFlatten(poSubGeom->getGeometryType());
        if( OGR_GT_IsCurve(eType) )
        {
            const OGRCurve *poCurve = poSubGeom->toCurve();
            dfLength += poCurve->get_Length();
        }
        else if( OGR_GT_IsSubClassOf(eType, wkbMultiCurve) ||
                 eType == wkbGeometryCollection )
        {
            const OGRGeometryCollection *poColl = poSubGeom->toGeometryCollection();
            dfLength += poColl->get_Length();
        }
    }

    return dfLength;
}
Exemple #30
0
int OGR_G_GetGeometryCount( OGRGeometryH hGeom )

{
    switch( wkbFlatten(((OGRGeometry *) hGeom)->getGeometryType()) )
    {
      case wkbPolygon:
        if( ((OGRPolygon *)hGeom)->getExteriorRing() == NULL )
            return 0;
        else
            return ((OGRPolygon *)hGeom)->getNumInteriorRings() + 1;

      case wkbMultiPoint:
      case wkbMultiLineString:
      case wkbMultiPolygon:
      case wkbGeometryCollection:
        return ((OGRGeometryCollection *)hGeom)->getNumGeometries();

      default:
        return 0;
    }
}