Beispiel #1
0
void vtVegLayer::AddElementsFromLULC(vtLULCFile *pLULC)
{
	LULCSection *section;
	LULCPoly *poly;

	SetVegType(VLT_Density);

	//set projections
	vtProjection proj_new;
	proj_new.SetProjectionSimple(0, -1, EPSG_DATUM_WGS84);
	SetProjection(proj_new);

	// figure out the number of polygons in file
	uint size = 0;
	for (uint sec = 0; sec < pLULC->NumSections(); sec++)
	{
		section = pLULC->GetSection(sec);
		size = size + section->m_iNumPolys;
	}

	// Create density field
	m_field_density = m_pSet->AddField("Density", FT_Float);
	m_pSet->SetNumEntities(size);

	// get each poly from LULC file
	uint i, s, p, count = 0;
	float density=0;
	for (s = 0; s < pLULC->NumSections(); s++)
	{
		section = pLULC->GetSection(s);
		for (p = 0; p < section->m_iNumPolys; p++)
		{
			poly = section->m_pPoly + p;

			bool wild = false;
			switch (poly->Attribute)
			{
				case 42:	// forest
					wild = true;
					density = 1.0f;
					break;
				case 32:
				case 33:
					wild = true;
					density = 0.5;
					break;
				case 22:	// orchards
					wild = false;
					// no crops for now
					break;
				default:
					density = 0.0f;
					break;
			}
			DLine2 dline;
			dline.SetSize(poly->m_iCoords);

			// get Coords of LULCpoly and store as latlon, then save in VPoly
			for (i = 0; i < dline.GetSize(); i++)
				dline.SetAt(i, poly->m_p[i]);

			DPolygon2 dpoly;
			dpoly.push_back(dline);

			GetPS()->SetPolygon(count, dpoly);
			m_pSet->SetValue(count, m_field_density, density);

			count++;
		}
	}
}
Beispiel #2
0
void StructVisitorGML::endElement(const char *name)
{
	bool bGrabAttribute = false;
	const char *data = m_data.c_str();

	if (m_state == 7 && !strcmp(name, "Edge"))
	{
		m_iEdge++;
		m_state = 3;
	}
	else if (m_state == 6)	// inside Footprint innerBoundaryIs
	{
		if (!strcmp(name, "gml:coordinates"))
		{
			DLine2 line;
			DLine2FromString(data, line);
			m_Footprint.push_back(line);
		}
		else if (!strcmp(name, "gml:innerBoundaryIs"))
			m_state = 4;
	}
	else if (m_state == 5)	// inside Footprint outerBoundaryIs
	{
		if (!strcmp(name, "gml:coordinates"))
		{
			DLine2 line;
			DLine2FromString(data, line);
			m_Footprint.push_back(line);
		}
		else if (!strcmp(name, "gml:outerBoundaryIs"))
			m_state = 4;
	}
	else if (m_state == 4)	// inside Footprint
	{
		if (!strcmp(name, "Footprint"))
		{
			m_pLevel->SetFootprint(m_Footprint);
			m_state = 3;
		}
	}
	else if (m_state == 3 && !strcmp(name, "Level"))
	{
		m_state = 2;
		m_iLevel ++;
	}
	else if (m_state == 2)
	{
		if (!strcmp(name, "Building"))
		{
			m_state = 1;

			// do this once after we done adding levels
			m_pBuilding->DetermineLocalFootprints();

			m_pSA->Append(m_pStructure);
			m_pStructure = NULL;
		}
		else
			bGrabAttribute = true;
	}
	else if (m_state == 1 && (!strcmp(name, "SRS")))
	{
		m_pSA->m_proj.SetTextDescription("wkt", data);

		// This seems wrong - why would each .vtst file reset the global projection?
		// g_Conv.Setup(m_pSA->m_proj.GetUnits(), DPoint2(0,0));
	}
	else if (m_state == 10)
	{
		if (!strcmp(name, "Linear"))
		{
			m_state = 1;

			m_pSA->Append(m_pStructure);
			m_pStructure = NULL;
		}
	}
	else if (m_state == 11)
	{
		if (!strcmp(name, "gml:coordinates"))
		{
			DLine2 &fencepts = m_pFence->GetFencePoints();
			double x, y;
			while (sscanf(data, "%lf,%lf", &x, &y) == 2)
			{
				fencepts.Append(DPoint2(x,y));
				data = strchr(data, ' ');
				if (data)
					data++;
				else
					break;
			}
		}
		else if (!strcmp(name, "Path"))
			m_state = 10;
	}
	else if (m_state == 20)
	{
		if (!strcmp(name, "Imported"))
		{
			m_state = 1;
			m_pSA->Append(m_pStructure);
			m_pStructure = NULL;
		}
		else if (!strcmp(name, "Rotation"))
		{
			float fRot;
			sscanf(data, "%f", &fRot);
			m_pInstance->SetRotation(fRot);
		}
		else if (!strcmp(name, "Scale"))
		{
			float fScale;
			sscanf(data, "%f", &fScale);
			m_pInstance->SetScale(fScale);
		}
		else
			bGrabAttribute = true;
	}
	else if (m_state == 21)
	{
		if (!strcmp(name, "gml:coordinates"))
		{
			double x, y;
			sscanf(data, "%lf,%lf", &x, &y);
			m_pInstance->SetPoint(DPoint2(x,y));
		}
		else if (!strcmp(name, "Location"))
			m_state = 20;
	}

	// first check for Attribute nodes
	if (bGrabAttribute)
	{
		// save these elements as literal strings
		vtTag tag;
		tag.name = name;
		tag.value = data;
		m_pStructure->AddTag(tag);		// where does the tag go?
	}
}