Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
OGRPoint *getARCCenter(OGRPoint *ptStart, OGRPoint *ptArc, OGRPoint *ptEnd) {
  // FIXME precision
  double bx = ptStart->getX(); double by = ptStart->getY();
  double cx = ptArc->getX(); double cy = ptArc->getY();
  double dx = ptEnd->getX(); double dy = ptEnd->getY();
  double temp, bc, cd, det, x, y;

  temp = cx*cx+cy*cy;
  bc = (bx*bx + by*by - temp)/2.0;
  cd = (temp - dx*dx - dy*dy)/2.0;
  det = (bx-cx)*(cy-dy)-(cx-dx)*(by-cy);

  OGRPoint *center = new OGRPoint();

  if (fabs(det) < 1.0e-6) { // could not determin the determinante: too small
    return center;
  }
  det = 1/det;
  x = (bc*(cy-dy)-cd*(by-cy))*det;
  y = ((bx-cx)*cd-(cx-dx)*bc)*det;

  center->setX(x);
  center->setY(y);

  return center;
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
featureset_ptr ogr_datasource::features_at_point(coord2d const& pt) const
{
    if (!is_bound_) bind();
   
    if (dataset_ && layer_.is_valid())
    {
        OGRLayer* layer = layer_.layer();

        if (indexed_)
        {
            filter_at_point filter(pt);
            
            return featureset_ptr(new ogr_index_featureset<filter_at_point> (*dataset_,
                                                                             *layer,
                                                                             filter,
                                                                             index_name_,
                                                                             desc_.get_encoding(),
                                                                             multiple_geometries_));
        }
        else
        {
            OGRPoint point;
            point.setX (pt.x);
            point.setY (pt.y);

            return featureset_ptr(new ogr_featureset (*dataset_,
                                                      *layer,
                                                      point,
                                                      desc_.get_encoding(),
                                                      multiple_geometries_));
        }
    }

    return featureset_ptr();
}
Ejemplo n.º 5
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;
    }
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
OGRFeature *OGROpenAirLabelLayer::GetNextRawFeature()
{
    const char* pszLine;
    double dfLat = 0, dfLon = 0;
    int bHasCoord = FALSE;

    while(TRUE)
    {
        pszLine = CPLReadLine2L(fpOpenAir, 1024, NULL);
        if (pszLine == NULL)
            return NULL;

        if (pszLine[0] == '*' || pszLine[0] == '\0')
            continue;

        if (EQUALN(pszLine, "AC ", 3))
        {
            if (osCLASS.size() != 0)
            {
                osNAME = "";
                osCEILING = "";
                osFLOOR = "";
            }
            osCLASS = pszLine + 3;
        }
        else if (EQUALN(pszLine, "AN ", 3))
            osNAME = pszLine + 3;
        else if (EQUALN(pszLine, "AH ", 3))
            osCEILING = pszLine + 3;
        else if (EQUALN(pszLine, "AL ", 3))
            osFLOOR = pszLine + 3;
        else if (EQUALN(pszLine, "AT ", 3))
        {
            bHasCoord = OGROpenAirGetLatLon(pszLine + 3, dfLat, dfLon);
            break;
        }
    }

    OGRFeature* poFeature = new OGRFeature(poFeatureDefn);
    poFeature->SetField(0, osCLASS.c_str());
    poFeature->SetField(1, osNAME.c_str());
    poFeature->SetField(2, osFLOOR.c_str());
    poFeature->SetField(3, osCEILING.c_str());

    CPLString osStyle;
    osStyle.Printf("LABEL(t:\"%s\")", osNAME.c_str());
    poFeature->SetStyleString(osStyle.c_str());

    if (bHasCoord)
    {
        OGRPoint* poPoint = new OGRPoint(dfLon, dfLat);
        poPoint->assignSpatialReference(poSRS);
        poFeature->SetGeometryDirectly(poPoint);
    }

    poFeature->SetFID(nNextFID++);

    return poFeature;
}
Ejemplo n.º 8
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);
}
Ejemplo n.º 9
0
      ogrfeature(const xyh point):
	poFeature(OGRFeature::CreateFeature( poLayer->getLayerDefn() ))
      {
	poFeature->SetField( "Height", point.value);
	OGRPoint pt; // destroy ??
	pt.setX( point.row );
	pt.setY( point.col );
	poFeature->SetGeometry( &pt );
      }
Ejemplo n.º 10
0
OGRGeometry *OGRPoint::clone() const

{
    OGRPoint    *poNewPoint = new OGRPoint( x, y, z );

    poNewPoint->assignSpatialReference( getSpatialReference() );

    return poNewPoint;
}
bool GDALSpatialLinking::checkCentroid(OGRGeometry* geo, OGRGeometry * lead_geo)
{
	OGRPoint ct;
	if (int error = geo->Centroid(&ct) != OGRERR_NONE) {
		DM::Logger(DM::Warning) << "error calculationg ct " << error;
		return false;
	}
	return ct.Within(lead_geo);
}
Ejemplo n.º 12
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;

}
Ejemplo n.º 13
0
OGRGeometry *OGRPoint::clone() const

{
    OGRPoint    *poNewPoint = new OGRPoint( x, y, z );

    poNewPoint->assignSpatialReference( getSpatialReference() );
    poNewPoint->setCoordinateDimension( nCoordDimension );

    return poNewPoint;
}
Ejemplo n.º 14
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));
  }
}
Ejemplo n.º 15
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);
		}
	}
Ejemplo n.º 16
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);
		}
	}
Ejemplo n.º 17
0
 OGRFeature* create_point_feature(const Osmium::OSM::Node* node) {
     OGRFeature* feature = OGRFeature::CreateFeature(m_layer_point->GetLayerDefn());
     Osmium::Geometry::Point point(*node);
     OGRPoint* ogrgeom = Osmium::Geometry::create_ogr_geometry(point);
     ogrgeom->transform(m_transformation);
     feature->SetGeometryDirectly(ogrgeom);
     sprintf(longint, "%ld", node->id());
     feature->SetField("osm_id", longint);
     feature->SetField("z_order", calculate_z_order(node));
     feature->SetField("way_area", 0);
     return feature;
 }
Ejemplo n.º 18
0
OGRGeometry *OGRPoint::clone() const

{
    OGRPoint *poNewPoint = new (std::nothrow) OGRPoint( x, y, z, m );
    if( poNewPoint == NULL )
        return NULL;

    poNewPoint->assignSpatialReference( getSpatialReference() );
    poNewPoint->flags = flags;

    return poNewPoint;
}
Ejemplo n.º 19
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;
  }
Ejemplo n.º 20
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;
 }
Ejemplo n.º 21
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() ); 
    } 
} 
Ejemplo n.º 22
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;
}
Ejemplo n.º 23
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);
}
Ejemplo n.º 24
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 */
}
Ejemplo n.º 25
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();
}
Ejemplo n.º 26
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();
}
Ejemplo n.º 27
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;
	}
}
Ejemplo n.º 28
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();
	}
}
void GDALAddComponentViewContainer::run()
{
	int counter = 0;
	for (int i = 0; i < elements; i++) {
		OGRFeature * f = this->components.createFeature();
		f->SetField("persons", "that is me");
		OGRPoint pt;
		pt.setX( i );
		pt.setY( i );

		f->SetGeometry(&pt);
		if (counter == 100000) {
			counter = 0;
		}
		counter++;
	}
}
Ejemplo n.º 30
0
featureset_ptr ogr_datasource::features_at_point(coord2d const& pt, double tol) const
{
    if (!is_bound_) bind();

#ifdef MAPNIK_STATS
    mapnik::progress_timer __stats__(std::clog, "ogr_datasource::features_at_point");
#endif

    if (dataset_ && layer_.is_valid())
    {
        std::vector<attribute_descriptor> const& desc_ar = desc_.get_descriptors();
        // feature context (schema)
        mapnik::context_ptr ctx = boost::make_shared<mapnik::context_type>();

        std::vector<attribute_descriptor>::const_iterator itr = desc_ar.begin();
        std::vector<attribute_descriptor>::const_iterator end = desc_ar.end();
        for (; itr!=end; ++itr) ctx->push(itr->get_name());

        OGRLayer* layer = layer_.layer();

        if (indexed_)
        {
            filter_at_point filter(pt);

            return featureset_ptr(new ogr_index_featureset<filter_at_point> (ctx,
                                                                             *layer,
                                                                             filter,
                                                                             index_name_,
                                                                             desc_.get_encoding()));
        }
        else
        {
            OGRPoint point;
            point.setX (pt.x);
            point.setY (pt.y);

            return featureset_ptr(new ogr_featureset (ctx,
                                                      *layer,
                                                      point,
                                                      desc_.get_encoding()));
        }
    }

    return featureset_ptr();
}