예제 #1
0
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;
    }

    const 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;
        OGRPoint 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 )
        {
            poCurve->EndPoint(&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;
            }

            CPLDebug("GML", "reversing curve");
            ((OGRSimpleCurve*)poCurve)->reversePoints();
        }
        // Patch so that it matches exactly.
        ((OGRSimpleCurve*)poCurve)->setPoint(0, &end);
    }

    return oCC.addCurveDirectly(this, poCurve, bNeedRealloc);
}
예제 #2
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();
}
예제 #3
0
OGRErr OGRMultiPoint::exportToWkt( char ** ppszDstText ) const

{
    int         nMaxString = getNumGeometries() * 20 + 128;
    int         nRetLen = 0;

    if( getNumGeometries() == 0 )
    {
        *ppszDstText = CPLStrdup("MULTIPOINT(EMPTY)");
        return OGRERR_NONE;
    }

    *ppszDstText = (char *) VSIMalloc( nMaxString );
    if( *ppszDstText == NULL )
        return OGRERR_NOT_ENOUGH_MEMORY;

    sprintf( *ppszDstText, "%s (", getGeometryName() );

    for( int i = 0; i < getNumGeometries(); i++ )
    {
        OGRPoint        *poPoint = (OGRPoint *) getGeometryRef( i );

        if( i > 0 )
            strcat( *ppszDstText + nRetLen, "," );

        nRetLen += strlen(*ppszDstText + nRetLen);

        if( nMaxString < nRetLen + 100 )
        {
            nMaxString = nMaxString * 2;
            *ppszDstText = (char *) CPLRealloc(*ppszDstText,nMaxString);
        }

        if( poPoint->getCoordinateDimension() == 3 )
            OGRMakeWktCoordinate( *ppszDstText + nRetLen,
                                  poPoint->getX(),
                                  poPoint->getY(),
                                  poPoint->getZ() );
        else
            OGRMakeWktCoordinate( *ppszDstText + nRetLen,
                                  poPoint->getX(),
                                  poPoint->getY(),
                                  0.0 );
    }

    strcat( *ppszDstText+nRetLen, ")" );

    return OGRERR_NONE;
}
예제 #4
0
double OGRCompoundCurve::get_Area() const
{
    if( IsEmpty() || !get_IsClosed() )
        return 0;

    // Optimization for convex rings.
    if( IsConvex() )
    {
        // Compute area of shape without the circular segments.
        OGRPointIterator* poIter = getPointIterator();
        OGRLineString oLS;
        oLS.setNumPoints( getNumPoints() );
        OGRPoint p;
        for( int i = 0; poIter->getNextPoint(&p); i++ )
        {
            oLS.setPoint( i, p.getX(), p.getY() );
        }
        double dfArea = oLS.get_Area();
        delete poIter;

        // Add the area of the spherical segments.
        dfArea += get_AreaOfCurveSegments();

        return dfArea;
    }

    OGRLineString* poLS = CurveToLine();
    double dfArea = poLS->get_Area();
    delete poLS;

    return dfArea;
}
예제 #5
0
파일: tigerpoint.cpp 프로젝트: OSGeo/gdal
OGRErr TigerPoint::CreateFeature( OGRFeature *poFeature,
                                  int pointIndex)

{
    char        szRecord[OGR_TIGER_RECBUF_LEN];
    OGRPoint    *poPoint = poFeature->GetGeometryRef()->toPoint();

    if( !SetWriteModule( m_pszFileCode, psRTInfo->nRecordLength+2, poFeature ) )
        return OGRERR_FAILURE;

    memset( szRecord, ' ', psRTInfo->nRecordLength );

    WriteFields( psRTInfo, poFeature, szRecord );

    if( poPoint != nullptr
        && (poPoint->getGeometryType() == wkbPoint
            || poPoint->getGeometryType() == wkbPoint25D) ) {
        WritePoint( szRecord, pointIndex, poPoint->getX(), poPoint->getY() );
    } else {
        if (bRequireGeom) {
            return OGRERR_FAILURE;
        }
    }

    WriteRecord( szRecord, psRTInfo->nRecordLength, m_pszFileCode );

    return OGRERR_NONE;
}
예제 #6
0
파일: ogrpoint.cpp 프로젝트: Mavrx-inc/gdal
OGRBoolean OGRPoint::Equals( OGRGeometry * poOther ) const

{
    if( poOther== this )
        return TRUE;

    if( poOther->getGeometryType() != getGeometryType() )
        return FALSE;

    OGRPoint *poOPoint = dynamic_cast<OGRPoint *>(poOther);
    if( poOPoint == NULL )
    {
        CPLError(CE_Fatal, CPLE_AppDefined,
                 "dynamic_cast failed.  Expected OGRPoint.");
        return FALSE;
    }
    if( flags != poOPoint->flags )
        return FALSE;

    if( IsEmpty() )
        return TRUE;

    // Should eventually test the SRS.
    if( poOPoint->getX() != getX()
        || poOPoint->getY() != getY()
        || poOPoint->getZ() != getZ() )
        return FALSE;

    return TRUE;
}
예제 #7
0
    osg::Geometry* multiPointToDrawable(OGRMultiPoint* mpoint) const
    {
        osg::Geometry* geom = new osg::Geometry;

        osg::Geometry* pointGeom = new osg::Geometry();
        osg::Vec3Array* vertices = new osg::Vec3Array();

        vertices->reserve(mpoint->getNumGeometries());
        for (int i = 0; i < mpoint->getNumGeometries(); i++ )
        {
            OGRGeometry* ogrGeom = mpoint->getGeometryRef(i);
            OGRwkbGeometryType ogrGeomType = ogrGeom->getGeometryType();

            if (wkbPoint != ogrGeomType && wkbPoint25D != ogrGeomType)
                continue; // skip

            OGRPoint* points = static_cast<OGRPoint*>(ogrGeom);

            vertices->push_back(osg::Vec3(points->getX(), points->getY(), points->getZ()));
        }

        pointGeom->setVertexArray(vertices);
        pointGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, vertices->size()));

        if (pointGeom->getVertexArray())
        {
            OSG_INFO << "osgOgrFeature::multiPointToDrawable " << geom->getVertexArray()->getNumElements() << " vertexes"<< std::endl;
        }

        return pointGeom;
    }
예제 #8
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();
}
예제 #9
0
static unsigned long HashAirwayIntersectionFeatureFunc(const void* _feature)
{
    OGRFeature* feature = (OGRFeature*)_feature;
    OGRPoint* point = (OGRPoint*) feature->GetGeometryRef();
    unsigned long hash = CPLHashSetHashStr((unsigned char*)feature->GetFieldAsString(0));
    const double x = point->getX();
    const double y = point->getY();
    return hash ^ OGRXPlaneAirwayHashDouble(x) ^ OGRXPlaneAirwayHashDouble(y);
}
예제 #10
0
OGRErr GTMWaypointLayer::CreateFeature (OGRFeature *poFeature)
{
    FILE* fp = poDS->getOutputFP();
    if (fp == NULL)
        return CE_Failure;

    OGRGeometry *poGeom = poFeature->GetGeometryRef();
    if ( poGeom == NULL )
    {
        CPLError( CE_Failure, CPLE_AppDefined,
                  "Features without geometry not supported by GTM writer in waypoints layer." );
        return OGRERR_FAILURE;
    }

    if (NULL != poCT)
    {
        poGeom = poGeom->clone();
        poGeom->transform( poCT );
    }


    switch( poGeom->getGeometryType() )
    {
    case wkbPoint:
    case wkbPoint25D:
    {
        OGRPoint* point = (OGRPoint*)poGeom;
        double lat = point->getY();
        double lon = point->getX();
        CheckAndFixCoordinatesValidity(lat, lon);
        poDS->checkBounds((float)lat, (float)lon);
        writeDouble(fp, lat);
        writeDouble(fp, lon);
        float altitude = 0.0;
        if (poGeom->getGeometryType() == wkbPoint25D)
            altitude = (float) point->getZ();

        WriteFeatureAttributes(poFeature, altitude);
        break;
    }

    default:
    {
        CPLError( CE_Failure, CPLE_NotSupported,
                  "Geometry type of `%s' not supported for 'waypoint' element.\n",
                  OGRGeometryTypeToName(poGeom->getGeometryType()) );
        return OGRERR_FAILURE;
    }
    }

    if (NULL != poCT)
        delete poGeom;

    return OGRERR_NONE;

}
예제 #11
0
    osg::Geometry* polygonToDrawable(OGRPolygon* polygon) const
    {
        osg::Geometry* geom = new osg::Geometry();
        osg::Vec3Array* vertices = new osg::Vec3Array();
        geom->setVertexArray(vertices);
        {
            OGRLinearRing *ring = polygon->getExteriorRing();
            OGRPoint point;
            for(int i = 0; i < ring->getNumPoints(); i++)
            {
                ring->getPoint(i, &point);
                vertices->push_back(osg::Vec3(point.getX(), point.getY(), point.getZ()));
            }
            geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, 0, vertices->size()));
        }

        if (polygon->getNumInteriorRings())
        {
            for (int i = 0; i < polygon->getNumInteriorRings(); i++)
            {
                OGRLinearRing *ring = polygon->getInteriorRing(i);
                OGRPoint point;
                for (int j = 0; j < ring->getNumPoints(); j++)
                {
                    ring->getPoint(j, &point);
                    vertices->push_back(osg::Vec3(point.getX(), point.getY(), point.getZ()));
                }
                geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, vertices->size()-ring->getNumPoints() , ring->getNumPoints()));
            }
        }
        osgUtil::Tessellator tsl;
        tsl.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);
        tsl.setBoundaryOnly(false);
        tsl.retessellatePolygons(*geom);

        osg::Vec3Array* array = triangulizeGeometry(geom);
        geom->setVertexArray(array);
        geom->removePrimitiveSet(0,geom->getNumPrimitiveSets());
        geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, array->size()));

        return geom;
    }
예제 #12
0
void GeometryPainter::_convertRingToQPolygon(const OGRLinearRing* ring, QPolygonF& qp,
  const QMatrix& m)
{
  OGRPoint p;
  qp.resize(ring->getNumPoints());
  for (int i = 0; i < ring->getNumPoints(); i++)
  {
    ring->getPoint(i, &p);
    qp[i] = QPointF(m.map(QPointF(p.getX(), p.getY())) - QPointF(0.5, 0.5));
  }
}
예제 #13
0
	void Shape::readRing(OGRLinearRing* ring, ShapePart& shapePart) {
		shapePart.points.resize(ring->getNumPoints());
		for (int j = 0; j < ring->getNumPoints(); ++j) {
			OGRPoint point;
			ring->getPoint(j, &point);

			shapePart.points[j].x = point.getX();
			shapePart.points[j].y = point.getY();
			updateBounds(&point);
		}
	}
예제 #14
0
	void Shape::readLineString(OGRLineString* lineString, ShapeObject& shapeObject) {
		shapeObject.parts.resize(1);
		shapeObject.parts[0].points.resize(lineString->getNumPoints());

		for (int i = 0; i < lineString->getNumPoints(); ++i) {
			OGRPoint point;
			lineString->getPoint(i, &point);
			shapeObject.parts[0].points[i].x = point.getX();
			shapeObject.parts[0].points[i].y = point.getY();
			updateBounds(&point);
		}
	}
예제 #15
0
  inline Usul::Math::Vec3d convertAndTransform ( const OGRPoint& point, OGRCoordinateTransformation* transform, double verticalOffset )
  {
    // Declare the point.
    Usul::Math::Vec3d p ( point.getX(), point.getY(), point.getZ() + verticalOffset );

    // Transform the point.
    if ( 0x0 != transform )
    {
      transform->Transform ( 1, &p[0], &p[1], &p[2] );
    }

    return p;
  }
예제 #16
0
void OGRLinearRing::reverseWindingOrder() 

{ 
    int pos = 0; 
    OGRPoint tempPoint; 

    for( int i = 0; i < nPointCount / 2; i++ ) 
    { 
        getPoint( i, &tempPoint ); 
        pos = nPointCount - i - 1;
        if( getCoordinateDimension() == 2 )
        {
            setPoint( i, getX(pos), getY(pos) );
            setPoint( pos, tempPoint.getX(), tempPoint.getY() );
        }
        else
        {
            setPoint( i, getX(pos), getY(pos), getZ(pos) );
            setPoint( pos, tempPoint.getX(), tempPoint.getY(), tempPoint.getZ() );
        }
    } 
} 
예제 #17
0
OGREnvelope wxGISShape::GetBounds() const
{
    OGREnvelope oReturnBounds;

    switch (m_eType)
    {
    case enumGISShapeTypeRectangle:
    case enumGISShapeTypePolygon:
    case enumGISShapeTypeLine:
    case enumGISShapeTypeEllipse:
    case enumGISShapeTypeMarker:
        oReturnBounds = m_oGeom.GetEnvelope();
        break;
    case enumGISShapeTypeCircle:
    {
        OGRGeometry *pGeom = m_oGeom;

        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()));
        oReturnBounds.MaxX = pCenterPt->getX() + dfRadius;
        oReturnBounds.MinX = pCenterPt->getX() - dfRadius;
        oReturnBounds.MaxY = pCenterPt->getY() + dfRadius;
        oReturnBounds.MinY = pCenterPt->getY() - dfRadius;
        break;
    }
#ifdef wxGIS_USE_SPLINE
    case enumGISShapeTypeCurve://TODO:
    case enumGISShapeTypeFreeHand:
        break;
#endif //wxGIS_USE_SPLINE
    case enumGISShapeTypeFreeHand:
        oReturnBounds = m_oGeom.GetEnvelope();
        break;
    };

    return oReturnBounds;
}
예제 #18
0
void GeometryPainter::drawLineString(QPainter& pt, const OGRLineString* lineString,
  const QMatrix& m)
{
  QPolygonF a(lineString->getNumPoints());

  OGRPoint point;
  for (int j = 0; j < lineString->getNumPoints(); j++)
  {
    lineString->getPoint(j, &point);
    a[j] = QPointF(m.map(QPointF(point.getX(), point.getY())) - QPointF(0.5, 0.5));
  }

  pt.drawPolyline(a);
}
예제 #19
0
void OGRLinearRing::reverseWindingOrder() 

{ 
    int pos = 0; 
    OGRPoint tempPoint; 

    for( int i = 0; i < nPointCount / 2; i++ ) 
    { 
        getPoint( i, &tempPoint ); 
        pos = nPointCount - i - 1; 
        setPoint( i, getX(pos), getY(pos), getZ(pos) ); 
        setPoint( pos, tempPoint.getX(), tempPoint.getY(), tempPoint.getZ() ); 
    } 
} 
예제 #20
0
OGRErr OGRDXFWriterLayer::WriteINSERT( OGRFeature *poFeature )

{
    WriteValue( 0, "INSERT" );
    WriteCore( poFeature );
    WriteValue( 100, "AcDbEntity" );
    WriteValue( 100, "AcDbBlockReference" );
    WriteValue( 2, poFeature->GetFieldAsString("BlockName") );
    
/* -------------------------------------------------------------------- */
/*      Write location.                                                 */
/* -------------------------------------------------------------------- */
    OGRPoint *poPoint = (OGRPoint *) poFeature->GetGeometryRef();

    WriteValue( 10, poPoint->getX() );
    if( !WriteValue( 20, poPoint->getY() ) ) 
        return OGRERR_FAILURE;

    if( poPoint->getGeometryType() == wkbPoint25D )
    {
        if( !WriteValue( 30, poPoint->getZ() ) )
            return OGRERR_FAILURE;
    }
    
/* -------------------------------------------------------------------- */
/*      Write scaling.                                                  */
/* -------------------------------------------------------------------- */
    int nScaleCount;
    const double *padfScale = 
        poFeature->GetFieldAsDoubleList( "BlockScale", &nScaleCount );

    if( nScaleCount == 3 )
    {
        WriteValue( 41, padfScale[0] );
        WriteValue( 42, padfScale[1] );
        WriteValue( 43, padfScale[2] );
    }

/* -------------------------------------------------------------------- */
/*      Write rotation.                                                 */
/* -------------------------------------------------------------------- */
    double dfAngle = poFeature->GetFieldAsDouble( "BlockAngle" );

    if( dfAngle != 0.0 )
    {
        WriteValue( 50, dfAngle ); // degrees
    }

    return OGRERR_NONE;
}
예제 #21
0
 osg::Geometry* linearRingToDrawable(OGRLinearRing* ring) const
 {
     osg::Geometry* contourGeom = new osg::Geometry();
     osg::Vec3Array* vertices = new osg::Vec3Array();
     OGRPoint point;
     for(int j = 0; j < ring->getNumPoints(); j++)
     {
         ring->getPoint(j, &point);
         vertices->push_back(osg::Vec3(point.getX(), point.getY(),point.getZ()));
     }
     contourGeom->setVertexArray(vertices);
     contourGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, 0, vertices->size()));
     return contourGeom;
 }
예제 #22
0
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 */
}
예제 #23
0
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;
	}
}
예제 #24
0
void MSN_Helper::LoadSamples(Config &config, Matrix &mat)
{
	if(config.bShapefile)
	{
		OGRRegisterAll();
		string pLayerName = StringGetFileName(config.sSamples);
		OGRDataSource* poDS = OGRSFDriverRegistrar::Open(config.sSamples.c_str(),FALSE);
		OGRLayer* poLayer = poDS->GetLayerByName(pLayerName.c_str());
	
		config.nSamples = poLayer->GetFeatureCount();
		mat.Resize(config.nSamples, 4);

		OGRPoint *poPoint;
		OGRFeature * pFeature =poLayer->GetNextFeature();
		for(unsigned long i=1; i<=config.nSamples; i++)
		{
			//样本取值字段名为value,double型
			poPoint = (OGRPoint *)pFeature->GetGeometryRef();
			mat[i][1] = poPoint->getX();
			mat[i][2] = poPoint->getY();
			mat[i][3] = pFeature->GetFieldAsInteger("stratum");
			mat[i][4] = pFeature->GetFieldAsDouble("value");
			pFeature = poLayer->GetNextFeature();
		}

		OGRDataSource::DestroyDataSource( poDS );
	}
	else
	{
		double x, y, v, stratum;
		string sline;
		ifstream infile(config.sSamples.c_str());
		infile >> config.nSamples;

		mat.Resize(config.nSamples, 4);
		for(unsigned long i=1; i<=config.nSamples; i++)
		{
			infile >> x >> y >> stratum >> v;
			mat[i][1] = x;
			mat[i][2] = y;
			mat[i][3] = stratum;
			mat[i][4] = v;
		}
		infile.close();
	}
}
예제 #25
0
osg::ref_ptr<osg::Group> MapExtruder::osg_assemble()
{
  	osg::ref_ptr<osg::Group> osg = new osg::Group;
	osg::ref_ptr<osg::Node> surface = osgDB::readNodeFile(_map2dFile);

	ExtrudeVisitor extrude(_height);
	surface->accept(extrude);
	osg->addChild(surface);

	int n = _sides ->getNumGeometries();
	osg::ref_ptr<osg::Geode> geode = new osg::Geode;			


	for(int i=0;i<n;i++)
	{
		osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
		osg::ref_ptr<osg::Vec3Array> verts = new osg::Vec3Array;

		std::vector<OGRPoint> points;
		OGRLinearRing *ring = ((OGRPolygon*)_sides->getGeometryRef(i))->getExteriorRing();
		int m = ring->getNumPoints();
		for(int j=0;j<m;j++)
		{
			OGRPoint pt;
			ring->getPoint(j,&pt);
			verts->push_back(osg::Vec3(pt.getX(),pt.getY(),pt.getZ()));
		}

		geom->setVertexArray(verts);
	
		osg::Vec4Array* colors = new osg::Vec4Array;
		colors->push_back(YELLOW);
		geom->setColorArray(colors);
		geom->setColorBinding(osg::Geometry::BIND_OVERALL);
    

		geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,m));
		geode->addDrawable(geom);
	}
	
	osg->addChild(geode);

	return osg;
}
예제 #26
0
파일: Template.cpp 프로젝트: dmm/cegis
// xSize and ySize should be in meters
Template::Template( int xSize, int ySize, const OGRPoint &center )
: mnXSize( xSize * PIX_PER_METER ),
  mnYSize( ySize * PIX_PER_METER )
{
   mpbBuf = new bool[ mnXSize * mnYSize ];

   for( int i=0; i<(mnXSize*mnYSize); ++i )
   {
      mpbBuf[i] = false;
   }

   // The center point minus half the size of the raster should work
   // as an offset for transforming projection coordinates onto the
   // raster.  I don't think my template images will ever be very big.
   // Currently I'm thinking 60 meters tops.
   mdXTrans = center.getX() - mnXSize/2;
   mdYTrans = center.getY() - mnYSize/2;

} // End Constructor
예제 #27
0
OGRErr OGRDXFWriterLayer::WritePOINT( OGRFeature *poFeature )

{
    WriteValue( 0, "POINT" );
    WriteCore( poFeature );
    WriteValue( 100, "AcDbEntity" );
    WriteValue( 100, "AcDbPoint" );

    // Write style pen color
    OGRStyleTool *poTool = nullptr;
    OGRStyleMgr oSM;
    if( poFeature->GetStyleString() != nullptr )
    {
        oSM.InitFromFeature( poFeature );

        if( oSM.GetPartCount() > 0 )
            poTool = oSM.GetPart(0);
    }
    if( poTool && poTool->GetType() == OGRSTCPen )
    {
        OGRStylePen *poPen = (OGRStylePen *) poTool;
        GBool  bDefault;

        if( poPen->Color(bDefault) != nullptr && !bDefault )
            WriteValue( 62, ColorStringToDXFColor( poPen->Color(bDefault) ) );
    }
    delete poTool;

    OGRPoint *poPoint = poFeature->GetGeometryRef()->toPoint();

    WriteValue( 10, poPoint->getX() );
    if( !WriteValue( 20, poPoint->getY() ) )
        return OGRERR_FAILURE;

    if( poPoint->getGeometryType() == wkbPoint25D )
    {
        if( !WriteValue( 30, poPoint->getZ() ) )
            return OGRERR_FAILURE;
    }

    return OGRERR_NONE;
}
예제 #28
0
OGRBoolean OGRPoint::Equals( OGRGeometry * poOther ) const

{
    OGRPoint    *poOPoint = (OGRPoint *) poOther;
    
    if( poOPoint== this )
        return TRUE;
    
    if( poOther->getGeometryType() != getGeometryType() )
        return FALSE;

    // we should eventually test the SRS.
    
    if( poOPoint->getX() != getX()
        || poOPoint->getY() != getY()
        || poOPoint->getZ() != getZ() )
        return FALSE;
    else
        return TRUE;
}
예제 #29
0
static int AddPoint( OGRGeometry *poGeometry, 
                     double dfX, double dfY, double dfZ, int nDimension )

{
    if( poGeometry->getGeometryType() == wkbPoint 
        || poGeometry->getGeometryType() == wkbPoint25D )
    {
        OGRPoint *poPoint = (OGRPoint *) poGeometry;

        if( poPoint->getX() != 0.0 || poPoint->getY() != 0.0 )
        {
            CPLError( CE_Failure, CPLE_AppDefined, 
                      "More than one coordinate for <Point> element.");
            return FALSE;
        }
            
        poPoint->setX( dfX );
        poPoint->setY( dfY );
        if( nDimension == 3 )
            poPoint->setZ( dfZ );

        return TRUE;
    }
                
    else if( poGeometry->getGeometryType() == wkbLineString
             || poGeometry->getGeometryType() == wkbLineString25D )
    {
        if( nDimension == 3 )
            ((OGRLineString *) poGeometry)->addPoint( dfX, dfY, dfZ );
        else
            ((OGRLineString *) poGeometry)->addPoint( dfX, dfY );

        return TRUE;
    }

    else
    {
        CPLAssert( FALSE );
        return FALSE;                                                   
    }
}
예제 #30
0
int OGRPolygon::PointOnSurface( OGRPoint *poPoint ) const

{
    if( poPoint == NULL )
        return OGRERR_FAILURE;

    OGRGeometryH hInsidePoint = OGR_G_PointOnSurface( (OGRGeometryH) this );
    if( hInsidePoint == NULL )
        return OGRERR_FAILURE;

    OGRPoint *poInsidePoint = (OGRPoint *) hInsidePoint;
    if( poInsidePoint->IsEmpty() )
        poPoint->empty();
    else
    {
        poPoint->setX( poInsidePoint->getX() );
        poPoint->setY( poInsidePoint->getY() );
    }

    return OGRERR_NONE;
}