Пример #1
0
    void object::test<11>()
    {
        char* wkt1 = "POINT(10 20)";
        err_ = OGR_G_CreateFromWkt(&wkt1, NULL, &g1_);
        ensure_equals("Can't import geometry from WKT", OGRERR_NONE, err_);
        ensure("Can't create geometry", NULL != g1_);

        char* wkt2 = "POINT(30 20)";
        err_ = OGR_G_CreateFromWkt(&wkt2, NULL, &g2_);
        ensure_equals("Can't import geometry from WKT", OGRERR_NONE, err_);
        ensure("Can't create geometry", NULL != g2_);

        g3_ = OGR_G_Union(g1_, g2_);
        ensure("OGR_G_Union failed with NULL", NULL != g3_);

        OGRGeometryH expect = NULL;
        char* wktExpect = "MULTIPOINT (10 20,30 20)";
        err_ = OGR_G_CreateFromWkt(&wktExpect, NULL, &expect);
        ensure_equals("Can't import geometry from WKT", OGRERR_NONE, err_);
        ensure("Can't create geometry", NULL != expect);

        // Compare operation result against expected geometry
        ensure_equal_geometries(g3_, expect, 0.0001);

        OGR_G_DestroyGeometry(expect);
    }
Пример #2
0
s_sat * sat_aoi(s_sat * sat, const char * shp_aoi_fname, const char * shp_forest_fname)
{
	try;

		OGRDataSourceH a_ds = NULL, f_ds = NULL;
		OGRLayerH a_layer = NULL, f_layer = NULL;
		OGRGeometryH a_geometry = NULL, fa_geometry = NULL, union_geometry = NULL, intersection_geometry = NULL, simplify_geometry = NULL;
		OGRFeatureH next_feature = NULL;
		s_sat * fa_img = NULL;

		throw_null((a_ds = OGR_Dr_Open(drv_shp, shp_aoi_fname, FALSE)));
		throw_null((f_ds = OGR_Dr_Open(drv_shp, shp_forest_fname, FALSE)));

		throw_null((a_layer = OGR_DS_GetLayer(a_ds, 0)));
		throw_null((f_layer = OGR_DS_GetLayer(f_ds, 0)));

		throw_null((a_geometry = OGR_G_CreateGeometry(wkbPolygon)));
		throw_null((fa_geometry = OGR_G_CreateGeometry(wkbPolygon)));

		OGR_L_ResetReading(a_layer);
		
		while((next_feature = OGR_L_GetNextFeature(a_layer)) != NULL)
		{
			throw_null((union_geometry = OGR_G_Union(a_geometry, OGR_F_GetGeometryRef(next_feature))));

			OGR_G_DestroyGeometry(a_geometry);

			a_geometry = union_geometry;

			union_geometry = NULL;
		}

		OGR_L_SetSpatialFilter(f_layer, a_geometry);
		OGR_L_ResetReading(f_layer);

		while((next_feature = OGR_L_GetNextFeature(f_layer)) != NULL)
		{
			throw_null((intersection_geometry = OGR_G_Intersection(a_geometry, OGR_F_GetGeometryRef(next_feature))));
			throw_null((union_geometry = OGR_G_Union(fa_geometry, intersection_geometry)));

			OGR_G_DestroyGeometry(intersection_geometry);
			OGR_G_DestroyGeometry(fa_geometry);

			fa_geometry = union_geometry;

			union_geometry = intersection_geometry = NULL;
		}

		throw_null((simplify_geometry = OGR_G_Simplify(fa_geometry, 0)));
		
		OGR_G_DestroyGeometry(fa_geometry);

		fa_geometry = simplify_geometry;

		simplify_geometry = NULL;

		throw_null((fa_img = sat_rasterize_copy(sat, fa_geometry)));

	catch;

		sat_destroy(fa_img);

		fa_img = NULL;

	finally;

		if(next_feature != NULL)
			OGR_F_Destroy(next_feature);

		if(a_geometry != NULL)
			OGR_G_DestroyGeometry(a_geometry);

		if(fa_geometry != NULL)
			OGR_G_DestroyGeometry(fa_geometry);

		if(union_geometry != NULL)
			OGR_G_DestroyGeometry(union_geometry);

		if(intersection_geometry != NULL)
			OGR_G_DestroyGeometry(intersection_geometry);

		if(simplify_geometry != NULL)
			OGR_G_DestroyGeometry(simplify_geometry);
		
		if(a_ds != NULL)
			OGRReleaseDataSource(a_ds);

		if(f_ds != NULL)
			OGRReleaseDataSource(f_ds);

	return fa_img;
}