Ejemplo n.º 1
0
int mapCRS2MINI(const vtProjection &proj)
{
    const char *crsname=proj.GetAttrValue("PROJECTION");

    if (proj.IsGeographic()) return(1);
    else if (proj.GetUTMZone()!=0) return(2);
    else if (EQUAL(crsname,SRS_PT_MERCATOR_1SP)) return(3);

    return(0);
}
Ejemplo n.º 2
0
bool WriteTilesetHeader(const char *filename, int cols, int rows, int lod0size,
						const DRECT &area, const vtProjection &proj,
						float minheight, float maxheight,
						LODMap *lodmap, bool bJPEG)
{
	FILE *fp = vtFileOpen(filename, "wb");
	if (!fp)
		return false;

	fprintf(fp, "[TilesetDescription]\n");
	fprintf(fp, "Columns=%d\n", cols);
	fprintf(fp, "Rows=%d\n", rows);
	fprintf(fp, "LOD0_Size=%d\n", lod0size);
	fprintf(fp, "Extent_Left=%.16lg\n", area.left);
	fprintf(fp, "Extent_Right=%.16lg\n", area.right);
	fprintf(fp, "Extent_Bottom=%.16lg\n", area.bottom);
	fprintf(fp, "Extent_Top=%.16lg\n", area.top);
	// write CRS, but pretty it up a bit
	OGRSpatialReference *poSimpleClone = proj.Clone();
	poSimpleClone->GetRoot()->StripNodes( "AXIS" );
	poSimpleClone->GetRoot()->StripNodes( "AUTHORITY" );
	char *wkt;
	poSimpleClone->exportToWkt(&wkt);
	fprintf(fp, "CRS=%s\n", wkt);
	OGRFree(wkt);	// Free CRS
	delete poSimpleClone;

	// For elevation tilesets, also write vertical extents
	if (minheight != INVALID_ELEVATION)
	{
		fprintf(fp, "Elevation_Min=%.f\n", minheight);
		fprintf(fp, "Elevation_Max=%.f\n", maxheight);
	}

	if (lodmap != NULL)
	{
		int mmin, mmax;
		for (int i = 0; i < rows; i++)
		{
			fprintf(fp, "RowLODs %2d:", i);
			for (int j = 0; j < cols; j++)
			{
				lodmap->get(j, i, mmin, mmax);
				fprintf(fp, " %d/%d", mmin, mmax);
			}
			fprintf(fp, "\n");
		}
	}

	// create a transformation that will map from the current projection to Lat/Lon WGS84
	vtProjection proj_llwgs84;
	proj_llwgs84.SetWellKnownGeogCS("WGS84");
	OCT *LLWGS84transform=CreateCoordTransform(&proj,&proj_llwgs84);

	// write center point of the tileset in Lat/Lon WGS84
	// this is helpful for libMini to compute an approximate translation
	double cx=(area.left+area.right)/2;
	double cy=(area.bottom+area.top)/2;
	if (LLWGS84transform->Transform(1,&cx,&cy)==1)
		fprintf(fp, "CenterPoint_LLWGS84=(%.16lg,%.16lg)\n",cx,cy);

	// write north point of the tileset in Lat/Lon WGS84
	// this is helpful for libMini to compute an approximate rotation
	double nx=(area.left+area.right)/2;
	double ny=area.top;
	if (LLWGS84transform->Transform(1,&nx,&ny)==1)
		fprintf(fp, "NorthPoint_LLWGS84=(%.16lg,%.16lg)\n",nx,ny);

	// delete Lat/Lon WGS84 transformation
	delete LLWGS84transform;

	// write CRS info
	// this is helpful for libMini to easily identify the coordinate reference system
	// supported CRS are: Geographic, UTM, Mercator
	const int crs=mapCRS2MINI(proj);
	const int datum=mapEPSG2MINI(proj.GetDatum());
	const int utmzone=proj.GetUTMZone();
	fprintf(fp, "CoordSys=(%d,%d,%d)\n",crs,datum,utmzone);

	if (bJPEG)
		fprintf(fp, "Format=JPEG\n");
	else
		fprintf(fp, "Format=DB\n");

	fclose(fp);

	return true;
}