Ejemplo n.º 1
0
OGRGeometry* BuildOgrPolygon(Polygon* poly, OGRCoordinateTransformation* transform)
{
    OGRPolygon* result = new OGRPolygon();

    list<Point*>* pOuter = poly->outerRing;
    list<Point*>::iterator ringIter;
    OGRLinearRing* ring = new OGRLinearRing();
    for (ringIter = pOuter->begin(); ringIter != pOuter->end(); ringIter++) {
        double x = (*ringIter)->X;
        double y = (*ringIter)->Y;
        if (transform != NULL)
            transform->Transform(1, &x, &y);
        ring->addPoint(x, y);
    }
    result->addRingDirectly(ring);

    list<list<Point *>*>* innerRings = poly->innerRings;
    list<list<Point *>*>::iterator ringsIter;
    for (ringsIter = innerRings->begin(); ringsIter != innerRings->end(); ringsIter++) {
        ring = new OGRLinearRing();
        list<Point*>* currRing = *ringsIter;
        for (ringIter = currRing->begin(); ringIter != currRing->end(); ringIter++) {
            double x = (*ringIter)->X;
            double y = (*ringIter)->Y;
            if (transform != NULL)
                transform->Transform(1, &x, &y);
            ring->addPoint(x, y);
        }
        result->addRingDirectly(ring);
    }

    result->closeRings();
    return result;
}
Ejemplo n.º 2
0
int OGRSQLiteSelectLayer::TestCapability( const char * pszCap )

{
    if (EQUAL(pszCap,OLCFastSpatialFilter))
    {
        if (osSQLCurrent != osSQLBase)
            return TRUE;

        size_t i = 0;
        OGRSQLiteLayer* poBaseLayer = GetBaseLayer(i);
        if (poBaseLayer == NULL)
        {
            CPLDebug("SQLITE", "Cannot find base layer");
            return FALSE;
        }

        OGRPolygon oFakePoly;
        const char* pszWKT = "POLYGON((0 0,0 1,1 1,1 0,0 0))";
        oFakePoly.importFromWkt((char**) &pszWKT);
        CPLString    osSpatialWhere = poBaseLayer->GetSpatialWhere(&oFakePoly);

        return osSpatialWhere.size() != 0;
    }
    else
        return OGRSQLiteLayer::TestCapability( pszCap );
}
Ejemplo n.º 3
0
static
OGRGeometry *kml2geom_latlonbox_int (
    LatLonBoxPtr poKmlLatLonBox,
    OGRSpatialReference *poOgrSRS)

{
    OGRPolygon *poOgrPolygon;
    double north, south, east, west;
    if ( !poKmlLatLonBox->has_north (  ) ||
         !poKmlLatLonBox->has_south (  ) ||
         !poKmlLatLonBox->has_east (  ) ||
         !poKmlLatLonBox->has_west (  ) ) {

        return NULL;
    }
    poOgrPolygon = new OGRPolygon (  );
    north = poKmlLatLonBox->get_north (  );
    south = poKmlLatLonBox->get_south (  );
    east = poKmlLatLonBox->get_east (  );
    west = poKmlLatLonBox->get_west (  );
    OGRLinearRing* poOgrRing = new OGRLinearRing (  );
    poOgrRing->addPoint ( east, north, 0.0 );
    poOgrRing->addPoint ( east, south, 0.0 );
    poOgrRing->addPoint ( west, south, 0.0 );
    poOgrRing->addPoint ( west, north, 0.0 );
    poOgrRing->addPoint ( east, north, 0.0 );
    poOgrPolygon->
        addRingDirectly ( poOgrRing );
    poOgrPolygon->assignSpatialReference(poOgrSRS);

    return poOgrPolygon;
}
Ejemplo n.º 4
0
/** @brief Extract bounding box from shape
  *
  * get bounding box as OGREnvelope from polygon shape in OGRFeature
  */
OGREnvelope* getBBoxOfShape(OGRFeature* poFeature)
{

    OGRGeometry *poGeometry;

    poGeometry = poFeature->GetGeometryRef();

    cout <<"extracting shape of " << poFeature->GetFieldAsString(1) << endl;

    if (poGeometry != NULL
            && wkbFlatten(poGeometry->getGeometryType()) == wkbPolygon)
    {
        OGRPolygon *poPoly = (OGRPolygon *) poGeometry;
        OGREnvelope *poEnv = new OGREnvelope();

        poPoly->getEnvelope(poEnv);
        return poEnv;
//                ofstream outfile ("outfile.kml");
//                double s = poEnv->MaxY;
//                double n = poEnv->MinY;
//                double e = poEnv->MaxX;
//                double w = poEnv->MinX;
//
//                cout<< s << ", " << n << " to " << e << ", " << w << endl;

//                outfile.close();
//                    cout << poPoint->getX() <<", "<<poPoint->getY()<<endl;
    }
    else
    {
        cout << "No point Geometry"<<endl;
        return NULL;
    }

}
Ejemplo n.º 5
0
OGRBoolean OGRPolygon::Equal( OGRGeometry * poOther )

{
    OGRPolygon *poOPoly = (OGRPolygon *) poOther;

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

    if( getNumInteriorRings() != poOPoly->getNumInteriorRings() )
        return FALSE;

    if( !getExteriorRing()->Equal( poOPoly->getExteriorRing() ) )
        return FALSE;
    
    // we should eventually test the SRS.

    for( int iRing = 0; iRing < getNumInteriorRings(); iRing++ )
    {
        if( !getInteriorRing(iRing)->Equal(poOPoly->getInteriorRing(iRing)) )
            return FALSE;
    }

    return TRUE;
}
Ejemplo n.º 6
0
int ICLayerLineString::isSelected(double x, double y, double scale)
{
  OGRPolygon* Poly =
      static_cast<OGRPolygon*> (OGRGeometryFactory::createGeometry(wkbPolygon));

  OGRLinearRing* Ring =
      static_cast<OGRLinearRing*> (OGRGeometryFactory::createGeometry(
          wkbLinearRing));

  Ring->setPoint(0, new OGRPoint(x - 3 / scale, y - 3 / scale));
  Ring->setPoint(1, new OGRPoint(x + 3 / scale, y - 3 / scale));
  Ring->setPoint(2, new OGRPoint(x + 3 / scale, y + 3 / scale));
  Ring->setPoint(3, new OGRPoint(x - 3 / scale, y + 3 / scale));

  Ring->closeRings();

  Poly->addRingDirectly(Ring);

  std::map<int, ICLayerObject*>::iterator it;
  for (it = m_ICLayerObject.begin(); it != m_ICLayerObject.end(); it++)
  {
    if (Poly->Intersects(
        static_cast<OGRGeometry*> ((*it).second->getOGRGeometryObject())))
    {
      return (*it).first;
    }
  }
  return -1;

}
Ejemplo n.º 7
0
OGRPolygon* OGRMSSQLGeometryParser::ReadPolygon(int iShape)
{
    int iFigure, iPoint, iNextPoint, i;
    int iNextFigure = NextFigureOffset(iShape);
    
    OGRPolygon* poPoly = new OGRPolygon();
    for (iFigure = FigureOffset(iShape); iFigure < iNextFigure; iFigure++)
    {
        OGRLinearRing* poRing = new OGRLinearRing();
        iPoint = PointOffset(iFigure);
        iNextPoint = NextPointOffset(iFigure);
        poRing->setNumPoints(iNextPoint - iPoint);
        i = 0;
        while (iPoint < iNextPoint)
        {
            if ( chProps & SP_HASZVALUES )
                poRing->setPoint(i, ReadX(iPoint), ReadY(iPoint), ReadZ(iPoint) );
            else
                poRing->setPoint(i, ReadX(iPoint), ReadY(iPoint) );

            ++iPoint;
            ++i;
        }
        poPoly->addRingDirectly( poRing );
    }
    return poPoly;
}
Ejemplo n.º 8
0
 OGRPolygon* make()
 {
     OGRPolygon* poPolygon = new OGRPolygon();
     
     poPolygon->addRingDirectly(make<OGRLinearRing>());
     poPolygon->addRingDirectly(make<OGRLinearRing>());
     
     return poPolygon;
 }
Ejemplo n.º 9
0
Polygon::Polygon(const BOX3D& box)
{
    OGRPolygon *poly = new OGRPolygon();
    m_geom.reset(poly);
    OGRLinearRing *lr = new OGRLinearRing();
    lr->addPoint(box.minx, box.miny, box.minz);
    lr->addPoint(box.minx, box.maxy, box.minz);
    lr->addPoint(box.maxx, box.maxy, box.maxz);
    lr->addPoint(box.maxx, box.miny, box.maxz);
    lr->addPoint(box.minx, box.miny, box.minz);
    poly->addRingDirectly(lr);
}
Ejemplo n.º 10
0
    void object::test<2>()
    {
        char* wkt = "POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1, 2 1, 2 2, 1 2,1 1))";
        OGRPolygon geom;
        err_ = geom.importFromWkt(&wkt);
        ensure_equals("Can't import geometry from WKT", OGRERR_NONE, err_);

        GEOSGeom geosGeom = geom.exportToGEOS();
        ensure("Can't export geometry to GEOS", NULL != geosGeom);

        GEOSGeom_destroy(geosGeom);
    }
Ejemplo n.º 11
0
OGRPolygon* OGRCurvePolygon::CurvePolyToPoly(double dfMaxAngleStepSizeDegrees,
                                             const char* const* papszOptions) const
{
    OGRPolygon* poPoly = new OGRPolygon();
    poPoly->assignSpatialReference(getSpatialReference());
    for( int iRing = 0; iRing < oCC.nCurveCount; iRing++ )
    {
        OGRLineString* poLS = oCC.papoCurves[iRing]->CurveToLine(dfMaxAngleStepSizeDegrees,
                                                                 papszOptions);
        poPoly->addRingDirectly(OGRCurve::CastToLinearRing(poLS));
    }
    return poPoly;
}
Ejemplo n.º 12
0
OGRPolygon *getPolygon(DOMElement *elem) {
  OGRPolygon *pg = new OGRPolygon();

  DOMElement *boundaryElem = (DOMElement *)elem->getFirstChild(); // outer boundary
  while (boundaryElem != NULL) {
    char* pszTagName = XMLString::transcode(boundaryElem->getTagName());
    if (cmpStr(ILI2_BOUNDARY, pszTagName) == 0)
      pg->addRingDirectly(getBoundary(boundaryElem));
    XMLString::release(&pszTagName);
    boundaryElem = (DOMElement *)boundaryElem->getNextSibling(); // inner boundaries
  }

  return pg;
}
Ejemplo n.º 13
0
double OGRMultiPolygon::get_Area() const

{
    double dfArea = 0.0;
    int iPoly;

    for( iPoly = 0; iPoly < getNumGeometries(); iPoly++ )
    {
        OGRPolygon *poPoly = (OGRPolygon *) getGeometryRef( iPoly );

        dfArea += poPoly->get_Area();
    }

    return dfArea;
}
Ejemplo n.º 14
0
OGRGeometry *OGRPolygon::clone()

{
    OGRPolygon	*poNewPolygon;

    poNewPolygon = new OGRPolygon;
    poNewPolygon->assignSpatialReference( getSpatialReference() );

    for( int i = 0; i < nRingCount; i++ )
    {
        poNewPolygon->addRing( papoRings[i] );
    }

    return poNewPolygon;
}
Ejemplo n.º 15
0
//--------------------------------------------------------------
OGRPolygon
GeoData::MakeRect(double dfMinX, double dfMinY, 
				  double dfMaxX, double dfMaxY)
{
    OGRLinearRing oRing;
    OGRPolygon oPoly;
	
    oRing.addPoint(dfMinX, dfMinY);
    oRing.addPoint(dfMinX, dfMaxY);
    oRing.addPoint(dfMaxX, dfMaxY);
    oRing.addPoint(dfMaxX, dfMinY);
    oRing.addPoint(dfMinX, dfMinY);
	
    oPoly.addRing(&oRing);

	return oPoly;
}
Ejemplo n.º 16
0
void OGRLayer::SetSpatialFilterRect( double dfMinX, double dfMinY, 
                                     double dfMaxX, double dfMaxY )

{
    OGRLinearRing  oRing;
    OGRPolygon oPoly;

    oRing.addPoint( dfMinX, dfMinY );
    oRing.addPoint( dfMinX, dfMaxY );
    oRing.addPoint( dfMaxX, dfMaxY );
    oRing.addPoint( dfMaxX, dfMinY );
    oRing.addPoint( dfMinX, dfMinY );

    oPoly.addRing( &oRing );

    SetSpatialFilter( &oPoly );
}
Ejemplo n.º 17
0
OGRGeometry *OGRGeometryFactory::forceToPolygon( OGRGeometry *poGeom )

{
    if( poGeom == NULL )
        return NULL;

    if( wkbFlatten(poGeom->getGeometryType()) != wkbGeometryCollection
        || wkbFlatten(poGeom->getGeometryType()) != wkbMultiPolygon )
        return poGeom;

    // build an aggregated polygon from all the polygon rings in the container.
    OGRPolygon *poPolygon = new OGRPolygon();
    OGRGeometryCollection *poGC = (OGRGeometryCollection *) poGeom;
    int iGeom;

    for( iGeom = 0; iGeom < poGC->getNumGeometries(); iGeom++ )
    {
        if( wkbFlatten(poGC->getGeometryRef(iGeom)->getGeometryType()) 
            != wkbPolygon )
            continue;

        OGRPolygon *poOldPoly = (OGRPolygon *) poGC->getGeometryRef(iGeom);
        int   iRing;

        poPolygon->addRing( poOldPoly->getExteriorRing() );

        for( iRing = 0; iRing < poOldPoly->getNumInteriorRings(); iRing++ )
            poPolygon->addRing( poOldPoly->getInteriorRing( iRing ) );
    }
    
    delete poGC;

    return poPolygon;
}
Ejemplo n.º 18
0
void Polygon::simplify(double distance_tolerance, double area_tolerance)
{
    throwNoGeos();

    auto deleteSmallRings = [area_tolerance](OGRGeometry *geom)
    {
// Missing until GDAL 2.3.
//        OGRPolygon *poly = geom->toPolygon();
        OGRPolygon *poly = static_cast<OGRPolygon *>(geom);

        std::vector<int> deleteRings;
        for (int i = 0; i < poly->getNumInteriorRings(); ++i)
        {
            OGRLinearRing *lr = poly->getInteriorRing(i);
            if (lr->get_Area() < area_tolerance)
                deleteRings.push_back(i + 1);
        }
        // Note that interior rings are in a list with the exterior ring,
        // which is why the ring numbers are offset by one when used in
        // this context (what a mess).
        for (auto i : deleteRings)
// Missing until 2.3
//            poly->removeRing(i, true);
            OGR_G_RemoveGeometry(gdal::toHandle(poly), i, true);
    };

    OGRGeometry *g = m_geom->SimplifyPreserveTopology(distance_tolerance);
    m_geom.reset(g);

    OGRwkbGeometryType t = m_geom->getGeometryType();
    if (t == wkbPolygon || t == wkbPolygon25D)
        deleteSmallRings(m_geom.get());
    else if (t == wkbMultiPolygon || t == wkbMultiPolygon25D)
    {
// Missing until 2.3
/**
        OGRMultiPolygon *mpoly = m_geom->toMultiPolygon();
        for (auto it = mpoly->begin(); it != mpoly->end(); ++it)
            deleteSmallRings(*it);
**/
        OGRMultiPolygon *mpoly = static_cast<OGRMultiPolygon *>(m_geom.get());
        for (int i = 0; i < mpoly->getNumGeometries(); ++i)
            deleteSmallRings(mpoly->getGeometryRef(i));
    }
}
Ejemplo n.º 19
0
void OGRPLScenesLayer::SetMainFilterRect(double dfMinX, double dfMinY,
                                        double dfMaxX, double dfMaxY)
{
    delete poMainFilter;
    if( dfMinX == dfMaxX && dfMinY == dfMaxY )
        poMainFilter = new OGRPoint(dfMinX, dfMinY);
    else
    {
        OGRPolygon* poPolygon = new OGRPolygon();
        poMainFilter = poPolygon;
        OGRLinearRing* poLR = new OGRLinearRing;
        poPolygon->addRingDirectly(poLR);
        poLR->addPoint(dfMinX, dfMinY);
        poLR->addPoint(dfMinX, dfMaxY);
        poLR->addPoint(dfMaxX, dfMaxY);
        poLR->addPoint(dfMaxX, dfMinY);
        poLR->addPoint(dfMinX, dfMinY);
    }
    ResetReading();
}
Ejemplo n.º 20
0
	std::unique_ptr<OGRPoint> centroid(const osmium::Way& way) {

		std::unique_ptr<OGRLineString> ogr_linestring = m_factory.create_linestring(way);

		OGRPolygon polygon;
		polygon.addRing(static_cast<OGRLinearRing*>(ogr_linestring.get()));

		std::unique_ptr<OGRPoint> centroid(new OGRPoint);
		int ret = polygon.Centroid(centroid.get());
		if (ret != OGRERR_NONE) {
			std::cerr << "Couldn't calculate centroid of way = " << way.id() << ".\n";
			osmium::geometry_error e(std::string("Couldn't calculate centroid of way = ") + std::to_string(way.id()) + std::string(".\n"));
			throw e;
			return nullptr;
		} else {
			return centroid;
		}

		return nullptr;
	}
Ejemplo n.º 21
0
Surface* Building::extrude_envelope() const
{
    Surface* envelope = new Surface(SurfaceType::Envelope,0,_length,_width,_height);

    OGRLinearRing* ringFt = _footprint->getExteriorRing();
    if(ringFt->isClockwise())
         adjust_winding_ccw(ringFt);

    envelope->addChild(new Surface(SurfaceType::Footprint,_footprint,_length,_width,0.));
    //extrude roof
    OGRLinearRing* ringRoof = new OGRLinearRing;
    for(int i=0; i<ringFt->getNumPoints(); i++)
        ringRoof->addPoint(ringFt->getX(i),ringFt->getY(i),_height);

    OGRPolygon plyRoof;
    plyRoof.addRingDirectly(ringRoof);

    envelope->addChild(new Surface(SurfaceType::Roof,&plyRoof,_length,_width,0.));

    //extrude walls
    for(int i=0; i<ringFt->getNumPoints()-1; i++)
    {
        OGRLinearRing* ringWall = new OGRLinearRing;
        ringWall->addPoint(ringFt->getX(i),ringFt->getY(i),0);
        ringWall->addPoint(ringFt->getX(i+1),ringFt->getY(i+1),0);
        ringWall->addPoint(ringFt->getX(i+1),ringFt->getY(i+1),_height);
        ringWall->addPoint(ringFt->getX(i),ringFt->getY(i),_height);
        ringWall->addPoint(ringFt->getX(i),ringFt->getY(i),0);

        OGRPolygon plyWall;
        plyWall.addRingDirectly(ringWall);

        OGRPoint pt1(ringFt->getX(i),ringFt->getY(i),0);
        OGRPoint pt2(ringFt->getX(i+1),ringFt->getY(i+1),0);

        envelope->addChild(new Wall(&plyWall,pt1.Distance(&pt2),_height,&pt1,&pt2));

    }

    return envelope;
}
Ejemplo n.º 22
0
std::vector<Polygon::Ring> Polygon::interiorRings() const
{
    std::vector<Ring> rings;

    OGRwkbGeometryType t = m_geom->getGeometryType();
    if (t != wkbPolygon && t != wkbPolygon25D)
        throw pdal_error("Request for exterior ring on non-polygon.");

//    OGRPolygon *poly = m_geom->toPolygon();
     OGRPolygon *poly = static_cast<OGRPolygon *>(m_geom.get());
    for (int i = 0; i < poly->getNumInteriorRings(); ++i)
    {
        OGRLinearRing *er = poly->getInteriorRing(i);

        Ring r;
        for (int j = 0; j < er->getNumPoints(); ++j)
            r.push_back({er->getX(j), er->getY(j)});
        rings.push_back(r);
    }
    return rings;
}
Ejemplo n.º 23
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++]);
				}
			}
		}
	}
Ejemplo n.º 24
0
	void feed_way(const osmium::Way& way) {
		try {
			const char* building = way.tags().get_value_by_key("building");

			if (building && way.is_closed()) {
				std::unique_ptr<OGRLineString> ogr_linestring = m_factory.create_linestring(way);
				OGRFeature* feature = OGRFeature::CreateFeature(m_layer->GetLayerDefn());
				OGRPolygon polygon;
				polygon.addRing(static_cast<OGRLinearRing*>(ogr_linestring.get()));
				feature->SetGeometry(static_cast<OGRGeometry*>(&polygon));

				feature->SetField("way_id", static_cast<double>(way.id())); //TODO: node.id() is of type int64_t. is this ok?
				feature->SetField("lastchange", way.timestamp().to_iso().c_str());

				create_feature(feature);
			}

		} catch (osmium::geom::geometry_error& e) {
			catch_geometry_error(e, way);
		}
	}
Ejemplo n.º 25
0
OGRPolygon* OGRCurvePolygon::CastToPolygon(OGRCurvePolygon* poCP)
{
    for(int i=0;i<poCP->oCC.nCurveCount;i++)
    {
        poCP->oCC.papoCurves[i] = OGRCurve::CastToLinearRing(poCP->oCC.papoCurves[i]);
        if( poCP->oCC.papoCurves[i] == NULL )
        {
            delete poCP;
            return NULL;
        }
    }
    OGRPolygon* poPoly = new OGRPolygon();
    poPoly->setCoordinateDimension(poCP->getCoordinateDimension());
    poPoly->assignSpatialReference(poCP->getSpatialReference());
    poPoly->oCC.nCurveCount = poCP->oCC.nCurveCount;
    poPoly->oCC.papoCurves = poCP->oCC.papoCurves;
    poCP->oCC.nCurveCount = 0;
    poCP->oCC.papoCurves = NULL;
    delete poCP;
    return poPoly;
}
Ejemplo n.º 26
0
void MapExtruder::extrusion()
{
	_sides = new OGRMultiPolygon();

	int n = _map2d->getNumGeometries();
	for(int i=0;i<n;i++)
	{

		OGRLinearRing* ring = ((OGRPolygon*)_map2d->getGeometryRef(i))->getExteriorRing();
		ring->closeRings();
		int nPoints = ring->getNumPoints();


		for(int j=0;j<nPoints-1;j++)
		{
			
			OGRPolygon side;
			OGRLinearRing* ring_side = new OGRLinearRing();

			OGRPoint p1,p4;

			ring->getPoint(j,&p1);
			ring->getPoint(j+1,&p4);

			OGRPoint p2(p1.getX(),p1.getY(),_height);
			OGRPoint p3(p4.getX(),p4.getY(),_height);
			
			
	
			ring_side->addPoint(&p1);			
		    ring_side->addPoint(&p2);
			ring_side->addPoint(&p3);
			ring_side->addPoint(&p4);
			ring_side->addPoint(&p1);

			side.addRing(ring_side);
			_sides->addGeometry(&side);
		}
	}
}
	void feed_way(const osmium::Way& way) {
		try {
			const char* building = way.tags().get_value_by_key("building");
			if (building && way.is_closed()) {
				const char* street   = way.tags().get_value_by_key("addr:street");
				const char* houseno  = way.tags().get_value_by_key("addr:housenumber");
				
				if (street || houseno) {
					std::unique_ptr<OGRLineString> ogr_linestring = m_factory.create_linestring(way);
					OGRFeature* feature = OGRFeature::CreateFeature(m_layer->GetLayerDefn());
					OGRPolygon polygon;
					polygon.addRing(static_cast<OGRLinearRing*>(ogr_linestring.get()));
					feature->SetGeometry(static_cast<OGRGeometry*>(&polygon));
					feature->SetField("way_id", static_cast<double>(way.id())); //TODO: node.id() is of type int64_t. is this ok?
					feature->SetField("lastchange", way.timestamp().to_iso().c_str());

					const char* postcode = way.tags().get_value_by_key("addr:postcode");
					const char* city     = way.tags().get_value_by_key("addr:city");
					const char* country  = way.tags().get_value_by_key("addr:country");
					const char* fulladdr = way.tags().get_value_by_key("addr:full");
					const char* place    = way.tags().get_value_by_key("addr:place");

					if (street)   { feature->SetField("street"  , street);   }
					if (houseno)  { feature->SetField("houseno" , houseno);  }
					if (postcode) { feature->SetField("postcode", postcode); }
					if (city)     { feature->SetField("city",     city);     }
					if (country)  { feature->SetField("country",  country);  }
					if (fulladdr) { feature->SetField("fulladdr", fulladdr); }
					if (place)    { feature->SetField("place",    place);    }

					create_feature(feature);

				}
			}
		}
		catch (osmium::geometry_error& e) {
			catch_geometry_error(e, way);
		}
	}
Ejemplo n.º 28
0
void report_raster_data_within_polygon(Raster* raster, OGRPolygon* poPolygon, int feature_num, string feature_name) {
    if (raster->rasterBBox->Intersects( poPolygon ) ) {
        OGRPolygon *poIntersection = (OGRPolygon*) raster->rasterBBox->Intersection( poPolygon );
        OGREnvelope* envl = new OGREnvelope;
        poIntersection->getEnvelope(envl);
        //printf ("Bounding rect (minX, maxX; minY, maxY): %.3f, %.3f; %.3f, %.3f\n", envl->MinX, envl->MaxX, envl->MinY, envl->MaxY);
        const double pw = raster->pixel_width;
        const double ph = raster->pixel_height;
        int pixelOffset_X = round((envl->MinX - raster->upper_left_x) / pw);
        int pixelOffset_Y = round((raster->upper_left_y - envl->MaxY) / ph);
        int nCellsX = round((envl->MaxX - raster->upper_left_x) / pw) - pixelOffset_X;
        int nCellsY = round((raster->upper_left_y - envl->MinY) / ph) - pixelOffset_Y;
        OGRPoint* pixelPoint = new OGRPoint(0,0);

        float* pPixelValue = (float *) CPLMalloc(sizeof(float));

        cerr << "Feature size: " << nCellsX << "x" << nCellsY << endl;
        for ( int row = 0; row < nCellsY; ++row ) {
            for ( int col = 0; col < nCellsX; ++col ) {
                double xcenter = (col + pixelOffset_X + 0.5)*pw + raster->upper_left_x;
                double ycenter = raster->upper_left_y - (row + pixelOffset_Y + 0.5)*ph;

                pixelPoint->setX(xcenter);
                pixelPoint->setY(ycenter);

                if ( pixelPoint->Intersects(poPolygon)) {
                    raster->band->RasterIO( GF_Read, pixelOffset_X + col, pixelOffset_Y + row, 1,1,  pPixelValue, 1,1, GDT_Float32, 0, 0 );
                    cout << setprecision(10) << xcenter << "," << setprecision(10) <<  ycenter << "," <<  *pPixelValue << "," << feature_num << ","  << feature_name << endl;
                } 
            }
        }
        delete envl;
        CPLFree(pPixelValue);
    } else {
        cerr << "Feature does not intersect raster" << endl;
    }
    return;
}
Ejemplo n.º 29
0
double Polygon::area() const
{
    throwNoGeos();

    OGRwkbGeometryType t = m_geom->getGeometryType();
// Not until GDAL 2.3
/**
    if (t == wkbPolygon || t == wkbPolygon25D)
        return m_geom->toPolygon()->get_Area();
    else if (t == wkbMultiPolygon || t == wkbMultiPolygon25D)
        return m_geom->toMultiPolygon()->get_Area();
**/
    if (t == wkbPolygon || t == wkbPolygon25D)
    {
        OGRPolygon *p = static_cast<OGRPolygon *>(m_geom.get());
        return p->get_Area();
    }
    else if (t == wkbMultiPolygon || t == wkbMultiPolygon25D)
    {
        OGRMultiPolygon *p = static_cast<OGRMultiPolygon *>(m_geom.get());
        return p->get_Area();
    }
    return 0;
}
Ejemplo n.º 30
0
static
OGRGeometry *kml2geom_latlonquad_int (
    GxLatLonQuadPtr poKmlLatLonQuad,
    OGRSpatialReference *poOgrSRS)

{
    if( !poKmlLatLonQuad->has_coordinates() )
        return NULL;

    const CoordinatesPtr& poKmlCoordinates =
        poKmlLatLonQuad->get_coordinates();

    OGRLinearRing* poOgrLinearRing = new OGRLinearRing (  );

    size_t nCoords = poKmlCoordinates->get_coordinates_array_size (  );
    for ( size_t i = 0; i < nCoords; i++ ) {
        Vec3 oKmlVec = poKmlCoordinates->get_coordinates_array_at ( i );
        if ( oKmlVec.has_altitude (  ) )
            poOgrLinearRing->
                addPoint ( oKmlVec.get_longitude (  ),
                           oKmlVec.get_latitude (  ),
                           oKmlVec.get_altitude (  ) );
        else
            poOgrLinearRing->
                addPoint ( oKmlVec.get_longitude (  ),
                           oKmlVec.get_latitude (  ) );
    }
    poOgrLinearRing->closeRings();

    OGRPolygon *poOgrPolygon = new OGRPolygon();
    poOgrPolygon->
        addRingDirectly ( poOgrLinearRing );
    poOgrPolygon->assignSpatialReference(poOgrSRS);

    return poOgrPolygon;
}