示例#1
0
//---------------------------------------------------------
bool CGPX_Import::Add_Point(CSG_MetaData *pNode, CSG_Shapes *pPoints)
{
	const SG_Char	*cString;
	TSG_Point		Point;

	if(	(cString = pNode->Get_Property(SG_T("lon"))) != NULL && CSG_String(cString).asDouble(Point.x)
	&&	(cString = pNode->Get_Property(SG_T("lat"))) != NULL && CSG_String(cString).asDouble(Point.y)
	&&	Add_Fields(pNode, pPoints) )
	{
		CSG_Shape	*pPoint	= pPoints->Add_Shape();

		pPoint->Add_Point(Point, 0);

		for(int i=0; i<pNode->Get_Children_Count(); i++)
		{
			CSG_MetaData	*pChild	= pNode->Get_Child(i);

			pPoint->Set_Value(pChild->Get_Name(), pChild->Get_Content());
		}

		if( m_bTime )
		{
			double		h	= CSG_String(pPoint->asString(SG_T("time"))).AfterFirst(SG_T('T')).asDouble();
			double		m	= CSG_String(pPoint->asString(SG_T("time"))).AfterFirst(SG_T(':')).asDouble();
			double		s	= CSG_String(pPoint->asString(SG_T("time"))).AfterLast (SG_T(':')).asDouble();

			pPoint->Set_Value(SG_T("dtime"), h + m / 60.0 + s / 3600.0);
		}

		return( true );
	}

	return( false );
}
示例#2
0
//---------------------------------------------------------
bool CGPX_Export::On_Execute(void)
{
	int				iEle, iName, iCmt, iDesc;
	CSG_String		File;
	CSG_MetaData	GPX;
	CSG_Shapes		*pShapes;

	//-----------------------------------------------------
	File		= Parameters("FILE")	->asString();
	pShapes		= Parameters("SHAPES")	->asShapes();

	iEle		= Parameters("ELE")		->asInt();	if( iEle  >= pShapes->Get_Field_Count() )	iEle	= -1;
	iName		= Parameters("NAME")	->asInt();	if( iName >= pShapes->Get_Field_Count() )	iName	= -1;
	iCmt		= Parameters("CMT")		->asInt();	if( iCmt  >= pShapes->Get_Field_Count() )	iCmt	= -1;
	iDesc		= Parameters("DESC")	->asInt();	if( iDesc >= pShapes->Get_Field_Count() )	iDesc	= -1;

	//-----------------------------------------------------
	GPX.Set_Name(SG_T("gpx"));
	GPX.Add_Property(SG_T("version")			, SG_T("1.0"));
	GPX.Add_Property(SG_T("creator")			, SG_T("SAGA - System for Automated Geoscientific Analyses - http://www.saga-gis.org"));
	GPX.Add_Property(SG_T("xmlns:xsi")			, SG_T("http://www.w3.org/2001/XMLSchema-instance"));
	GPX.Add_Property(SG_T("xmlns")				, SG_T("http://www.topografix.com/GPX/1/0"));
	GPX.Add_Property(SG_T("xsi:schemaLocation")	, SG_T("http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"));

	for(int iShape=0; iShape<pShapes->Get_Count(); iShape++)
	{
		CSG_Shape	*pShape	= pShapes->Get_Shape(iShape);

		for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
		{
			for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
			{
				CSG_MetaData	*pPoint	= GPX.Add_Child(SG_T("wpt"));

				pPoint->Add_Property(SG_T("lon"), pShape->Get_Point(iPoint, iPart).x);
				pPoint->Add_Property(SG_T("lat"), pShape->Get_Point(iPoint, iPart).y);

				if( iEle  > 0 )	pPoint->Add_Child(SG_T("ele" ), pShape->asString(iEle));
				if( iName > 0 )	pPoint->Add_Child(SG_T("name"), pShape->asString(iName));
				if( iCmt  > 0 )	pPoint->Add_Child(SG_T("cmt" ), pShape->asString(iCmt));
				if( iDesc > 0 )	pPoint->Add_Child(SG_T("desc"), pShape->asString(iDesc));
			}
		}
	}

	//-----------------------------------------------------
	if( !GPX.Save(File) )
	{
		return( false );
	}

	//-----------------------------------------------------
	return( true );
}
示例#3
0
//---------------------------------------------------------
wxString CWKSP_PointCloud::Get_Value(CSG_Point ptWorld, double Epsilon)
{
	CSG_Shape		*pShape;

	if( (pShape = m_pPointCloud->Get_Shape(ptWorld, Epsilon)) != NULL )
	{
		if( m_Color_Field >= 0 )
		{
			switch( m_pClassify->Get_Mode() )
			{
			case CLASSIFY_LUT:
				return( m_pClassify->Get_Class_Name_byValue(pShape->asDouble(m_Color_Field)) );

			case CLASSIFY_METRIC:	default:
				return( pShape->asString(m_Color_Field) );

			case CLASSIFY_RGB:
				double	Value = pShape->asDouble(m_Color_Field);
				return( wxString::Format(wxT("R%03d G%03d B%03d"), SG_GET_R((int)Value), SG_GET_G((int)Value), SG_GET_B((int)Value)) );
			}
		}
		else
		{
			return( wxString::Format(wxT("%s: %d"), LNG("[CAP] Index"), pShape->Get_Index() + 1) );
		}
	}

	return( LNG("") );
}
示例#4
0
//---------------------------------------------------------
bool CSurfer_BLN_Export::On_Execute(void)
{
	//-----------------------------------------------------
	CSG_File	Stream;

	if( !Stream.Open(Parameters("FILE")->asString(), SG_FILE_W) )
	{
		return( false );
	}

	CSG_Shapes	*pShapes	= Parameters("SHAPES")->asShapes();

	if( !pShapes->is_Valid() || pShapes->Get_Count() <= 0 )
	{
		return( false );
	}

	//-----------------------------------------------------
	int iName	= Parameters("BNAME" )->asBool() ? Parameters("NAME")->asInt() : -1;
	int iDesc	= Parameters("BDESC" )->asBool() ? Parameters("DESC")->asInt() : -1;
	int iZVal	= Parameters("BZVAL" )->asBool() ? Parameters("ZVAL")->asInt() : -1;

	int Flag	= 1;

	//-----------------------------------------------------
	for(int iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
	{
		CSG_Shape	*pShape	= pShapes->Get_Shape(iShape);

		for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
		{
			Stream.Printf(SG_T("%d,%d"), pShape->Get_Point_Count(iPart), Flag);

			if( iName >= 0 )	{	Stream.Printf(SG_T(",\"%s\""), pShape->asString(iName));	}
			if( iDesc >= 0 )	{	Stream.Printf(SG_T(",\"%s\""), pShape->asString(iDesc));	}

			Stream.Printf(SG_T("\n"));

			for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
			{
				TSG_Point	p	= pShape->Get_Point(iPoint, iPart);

				if( iZVal >= 0 )
				{
					Stream.Printf(SG_T("%f,%f,%f\n"), p.x, p.y, pShape->asDouble(iZVal));
				}
				else
				{
					Stream.Printf(SG_T("%f,%f\n"   ), p.x, p.y);
				}
			}
		}
	}

	//-----------------------------------------------------
	return( true );
}
示例#5
0
//---------------------------------------------------------
bool CPolygon_Dissolve::On_Execute(void)
{
	//-----------------------------------------------------
	CSG_Shapes	*pPolygons	= Parameters("POLYGONS")->asShapes();

	if(	!pPolygons->is_Valid() || pPolygons->Get_Count() < 2 )
	{
		Error_Set(_TL("invalid or empty polygons layer"));

		return( false );
	}

	//-----------------------------------------------------
	CSG_Shapes	*pUnions	= Parameters("DISSOLVED")->asShapes();

	pUnions->Create(SHAPE_TYPE_Polygon);

	int	Field_1	= Parameters("FIELD_1")->asInt();
	int	Field_2	= Parameters("FIELD_2")->asInt();	if( Field_1 < 0 )	Field_2	= -1;
	int	Field_3	= Parameters("FIELD_3")->asInt();	if( Field_2 < 0 )	Field_3	= -1;

	if( Field_1 >= 0 )
	{
		CSG_String	s	= pPolygons->Get_Field_Name(Field_1);
		pUnions->Add_Field(pPolygons->Get_Field_Name(Field_1), pPolygons->Get_Field_Type(Field_1));

		if( Field_2 >= 0 )
		{
			s	+= CSG_String(" | ") + pPolygons->Get_Field_Name(Field_2);
			pUnions->Add_Field(pPolygons->Get_Field_Name(Field_2), pPolygons->Get_Field_Type(Field_2));

			if( Field_3 >= 0 )
			{
				s	+= CSG_String(" | ") + pPolygons->Get_Field_Name(Field_3);
				pUnions->Add_Field(pPolygons->Get_Field_Name(Field_3), pPolygons->Get_Field_Type(Field_3));
			}
		}

		pPolygons->Set_Index(Field_1, TABLE_INDEX_Ascending, Field_2, TABLE_INDEX_Ascending, Field_3, TABLE_INDEX_Ascending);

		pUnions->Set_Name(CSG_String::Format(SG_T("%s [%s: %s]"), pPolygons->Get_Name(), _TL("Dissolved"), s.c_str()));
	}
	else // if( Field_1 < 0 )
	{
		pUnions->Set_Name(CSG_String::Format(SG_T("%s [%s: %s]"), pPolygons->Get_Name(), _TL("Dissolved"), _TL("All")));
	}

	Init_Statistics(pUnions, pPolygons);

	//-----------------------------------------------------
	CSG_String	Value;

	CSG_Shape	*pUnion		= NULL;

	bool		bDissolve	= Parameters("BND_KEEP")->asBool() == false;

	//-----------------------------------------------------
	for(int iPolygon=0; iPolygon<pPolygons->Get_Count() && Set_Progress(iPolygon, pPolygons->Get_Count()); iPolygon++)
	{
		CSG_Shape	*pPolygon	= pPolygons->Get_Shape(pPolygons->Get_Record_byIndex(iPolygon)->Get_Index());

		CSG_String	s;

		if( Field_1 >= 0 )	s	 = pPolygon->asString(Field_1);
		if( Field_2 >= 0 )	s	+= pPolygon->asString(Field_2);
		if( Field_3 >= 0 )	s	+= pPolygon->asString(Field_3);

		if( pUnion == NULL || (Field_1 >= 0 && Value.Cmp(s)) )
		{
			Set_Union(pUnion, bDissolve);

			Value	= s;
			pUnion	= pUnions->Add_Shape(pPolygon, SHAPE_COPY_GEOM);

			if( Field_1 >= 0 )	pUnion->Set_Value(0, pPolygon->asString(Field_1));
			if( Field_2 >= 0 )	pUnion->Set_Value(1, pPolygon->asString(Field_2));
			if( Field_3 >= 0 )	pUnion->Set_Value(2, pPolygon->asString(Field_3));

			Add_Statistics(pUnion, pPolygon, true);
		}
		else
		{
			for(int iPart=0; iPart<pPolygon->Get_Part_Count(); iPart++)
			{
				for(int iPoint=0, nParts=pUnion->Get_Part_Count(); iPoint<pPolygon->Get_Point_Count(iPart); iPoint++)
				{
					pUnion->Add_Point(pPolygon->Get_Point(iPoint, iPart), nParts);
				}
			}

			Add_Statistics(pUnion, pPolygon, false);
		}
	}

	Set_Union(pUnion, bDissolve);

	//-----------------------------------------------------
	if( m_Statistics )
	{
		delete[](m_Statistics);
	}

	m_List.Clear();

	return( pUnions->is_Valid() );
}
//---------------------------------------------------------
bool CAdd_Polygon_Attributes::On_Execute(void)
{
	//-----------------------------------------------------
	CSG_Shapes	*pInput		= Parameters("INPUT")->asShapes();

	if( !pInput->is_Valid() )
	{
		Error_Set(_TL("Invalid points layer."));

		return( false );
	}

	//-----------------------------------------------------
	CSG_Shapes	*pPolygons	= Parameters("POLYGONS")->asShapes();

	if( !pPolygons->is_Valid() )
	{
		Error_Set(_TL("Invalid polygon layer."));

		return( false );
	}

	//-----------------------------------------------------
	CSG_Parameter_Table_Fields	*pFields	= Parameters("FIELDS")->asTableFields();

	if( pFields->Get_Count() == 0 )
	{
		CSG_String	sFields;

		for(int iField=0; iField<pPolygons->Get_Field_Count(); iField++)
		{
			sFields += CSG_String::Format(SG_T("%d,"), iField);
		}

		pFields->Set_Value(sFields);
	}

	//-----------------------------------------------------
	CSG_Shapes	*pOutput	= Parameters("OUTPUT")->asShapes();

	if( pOutput && pOutput != pInput )
	{
		pOutput->Create(*pInput);
	}
	else
	{
		Parameters("OUTPUT")->Set_Value(pOutput	= pInput);
	}

	pOutput->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pInput->Get_Name(), pPolygons->Get_Name()));

	//-----------------------------------------------------
	int	outField	= pOutput->Get_Field_Count();

	{
		for(int iField=0; iField<pFields->Get_Count(); iField++)
		{
			int	jField	= pFields->Get_Index(iField);

			pOutput->Add_Field(pPolygons->Get_Field_Name(jField), pPolygons->Get_Field_Type(jField));
		}
	}

	//-----------------------------------------------------
	for(int iPoint=0; iPoint<pOutput->Get_Count() && Set_Progress(iPoint, pOutput->Get_Count()); iPoint++)
	{
		CSG_Shape	*pPoint		= pOutput	->Get_Shape(iPoint);
		CSG_Shape	*pPolygon	= pPolygons	->Get_Shape(pPoint->Get_Point(0));

		if( pPolygon )
		{
			for(int iField=0; iField<pFields->Get_Count(); iField++)
			{
				int	jField	= pFields->Get_Index(iField);

				switch( pPolygons->Get_Field_Type(jField) )
				{
				case SG_DATATYPE_String:
				case SG_DATATYPE_Date:
					pPoint->Set_Value(outField + iField, pPolygon->asString(jField));
					break;

				default:
					pPoint->Set_Value(outField + iField, pPolygon->asDouble(jField));
					break;
				}
			}
		}
	}

	//-----------------------------------------------------
	return( true );
}
示例#7
0
//---------------------------------------------------------
bool COGR_DataSource::Write_Shapes(CSG_Shapes *pShapes)
{
	OGRLayer	*pLayer;

	//-----------------------------------------------------
	if( m_pDataSource && pShapes && pShapes->is_Valid() && (pLayer = m_pDataSource->CreateLayer(SG_STR_SGTOMB(pShapes->Get_Name()), NULL, g_OGR_Driver.Get_Type(pShapes->Get_Type()))) != NULL )
	{
		bool			bResult	= true;
		int				iField;

		//-------------------------------------------------
		for(iField=0; iField<pShapes->Get_Field_Count() && bResult; iField++)
		{
			OGRFieldDefn	DefField(SG_STR_SGTOMB(pShapes->Get_Field_Name(iField)), g_OGR_Driver.Get_Type(pShapes->Get_Field_Type(iField)));

			//	DefField.SetWidth(32);

			if( pLayer->CreateField(&DefField) != OGRERR_NONE )
			{
				bResult	= false;
			}
		}

		//-------------------------------------------------
		for(int iShape=0; iShape<pShapes->Get_Count() && bResult && SG_UI_Process_Set_Progress(iShape, pShapes->Get_Count()); iShape++)
		{
			CSG_Shape	*pShape		= pShapes->Get_Shape(iShape);
			OGRFeature	*pFeature	= OGRFeature::CreateFeature(pLayer->GetLayerDefn());

			for(iField=0; iField<pShapes->Get_Field_Count(); iField++)
			{
				switch( pShapes->Get_Field_Type(iField) )
				{
				default:
				case SG_DATATYPE_Char:
				case SG_DATATYPE_String:
				case SG_DATATYPE_Date:
					pFeature->SetField(iField, SG_STR_SGTOMB(pShape->asString(iField)));
					break;

				case SG_DATATYPE_Short:
				case SG_DATATYPE_Int:
				case SG_DATATYPE_Long:
				case SG_DATATYPE_Color:
					pFeature->SetField(iField, pShape->asInt(iField));
					break;

				case SG_DATATYPE_Float:
				case SG_DATATYPE_Double:
					pFeature->SetField(iField, pShape->asDouble(iField));
					break;
				}
			}

			if( !_Write_Geometry(pShape, pFeature) || pLayer->CreateFeature(pFeature) != OGRERR_NONE )
			{
				bResult	= false;
			}

			OGRFeature::DestroyFeature(pFeature);
		}

		//-------------------------------------------------
		return( bResult );
	}

	return( false );
}
//---------------------------------------------------------
bool CAdd_Polygon_Attributes::On_Execute(void)
{
	int			inField, outField;
	CSG_Shapes	*pInput, *pOutput, *pPolygons;

	//-----------------------------------------------------
	pInput		= Parameters("INPUT")		->asShapes();
	pOutput		= Parameters("OUTPUT")		->asShapes();
	pPolygons	= Parameters("POLYGONS")	->asShapes();
	inField		= Parameters("FIELD")		->asInt();

	//-----------------------------------------------------
	if( !pInput->is_Valid() )
	{
		Message_Add(_TL("Invalid points layer."));

		return( false );
	}
	else if( !pPolygons->is_Valid() )
	{
		Message_Add(_TL("Invalid polygon layer."));

		return( false );
	}

	//-----------------------------------------------------
	if( pOutput && pOutput != pInput )
	{
		pOutput->Create(*pInput);
	}
	else
	{
		Parameters("RESULT")->Set_Value(pOutput	= pInput);
	}

	pOutput->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pInput->Get_Name(), pPolygons->Get_Name()));

	//-----------------------------------------------------
	outField	= pOutput->Get_Field_Count();

	if( inField >= 0 && inField < pPolygons->Get_Field_Count() )
	{	// add single attribute
		pOutput->Add_Field(pPolygons->Get_Field_Name(inField), pPolygons->Get_Field_Type(inField));
	}
	else
	{	// add all attributes
		inField	= -1;

		for(int iField=0; iField<pPolygons->Get_Field_Count(); iField++)
		{
			pOutput->Add_Field(pPolygons->Get_Field_Name(iField), pPolygons->Get_Field_Type(iField));
		}
	}

	//-----------------------------------------------------
	for(int iPoint=0; iPoint<pOutput->Get_Count() && Set_Progress(iPoint, pOutput->Get_Count()); iPoint++)
	{
		CSG_Shape	*pPoint		= pOutput	->Get_Shape(iPoint);
		CSG_Shape	*pPolygon	= pPolygons	->Get_Shape(pPoint->Get_Point(0));

		if( pPolygon )
		{
			if( inField >= 0 )
			{	// add single attribute
				pPoint->Set_Value(outField, pPolygon->asString(inField));
			}
			else
			{	// add all attributes
				for(int iField=0; iField<pPolygons->Get_Field_Count(); iField++)
				{
					switch( pPolygons->Get_Field_Type(iField) )
					{
					case SG_DATATYPE_String:
					case SG_DATATYPE_Date:
						pPoint->Set_Value(outField + iField, pPolygon->asString(iField));
						break;

					default:
						pPoint->Set_Value(outField + iField, pPolygon->asDouble(iField));
						break;
					}
				}
			}
		}
	}

	//-----------------------------------------------------
	return( true );
}
//---------------------------------------------------------
bool CLine_Dissolve::On_Execute(void)
{
	CSG_Shapes	*pLines	= Parameters("LINES")->asShapes();

	if(	!pLines->is_Valid() || pLines->Get_Count() < 2 )
	{
		Error_Set(_TL("invalid or empty lines layer"));

		return( false );
	}

	//-----------------------------------------------------
	CSG_Shapes	*pDissolved	= Parameters("DISSOLVED")->asShapes();

	pDissolved->Create(SHAPE_TYPE_Line);

	CSG_Parameter_Table_Fields	&Fields	= *Parameters("FIELDS")->asTableFields();

	CSG_Table	Dissolve;

	//-----------------------------------------------------
	if( Fields.Get_Count() == 0 )
	{
		pDissolved->Fmt_Name("%s [%s]", pLines->Get_Name(), _TL("Dissolved"));
	}
	else
	{
		Dissolve.Add_Field("INDEX", SG_DATATYPE_Int   );
		Dissolve.Add_Field("VALUE", SG_DATATYPE_String);

		Dissolve.Set_Record_Count(pLines->Get_Count());

		for(int i=0; i<pLines->Get_Count() && Set_Progress(i, pLines->Get_Count()); i++)
		{
			CSG_Shape	*pLine	= pLines->Get_Shape(i);

			CSG_String	Value;

			for(int iField=0; iField<Fields.Get_Count(); iField++)
			{
				Value	+= pLine->asString(Fields.Get_Index(iField));
			}

			Dissolve[i].Set_Value(0, i);
			Dissolve[i].Set_Value(1, Value);
		}

		Dissolve.Set_Index(1, TABLE_INDEX_Ascending);

		//-------------------------------------------------
		CSG_String	Name;

		for(int iField=0; iField<Fields.Get_Count(); iField++)
		{
			if( iField > 0 )
			{
				Name	+= "; ";
			}

			Name	+= pLines->Get_Field_Name(Fields.Get_Index(iField));

			pDissolved->Add_Field(
				pLines->Get_Field_Name(Fields.Get_Index(iField)),
				pLines->Get_Field_Type(Fields.Get_Index(iField))
			);
		}

		pDissolved->Fmt_Name("%s [%s: %s]", pLines->Get_Name(), _TL("Dissolved"), Name.c_str());
	}

	//-----------------------------------------------------
	Statistics_Initialize(pDissolved, pLines);

	//-----------------------------------------------------
	CSG_String	Value;	CSG_Shape	*pDissolve	= NULL;

	for(int i=0; i<pLines->Get_Count() && Set_Progress(i, pLines->Get_Count()); i++)
	{
		CSG_Shape	*pLine	= pLines->Get_Shape(!Dissolve.Get_Count() ? i : Dissolve[i].asInt(0));

		if( !pDissolve || (Dissolve.Get_Count() && Value.Cmp(Dissolve[i].asString(1))) )
		{
			if( Dissolve.Get_Count() )
			{
				Value	= Dissolve[i].asString(1);
			}

			pDissolve	= pDissolved->Add_Shape(pLine, SHAPE_COPY_GEOM);

			for(int iField=0; iField<Fields.Get_Count(); iField++)
			{
				*pDissolve->Get_Value(iField)	= *pLine->Get_Value(Fields.Get_Index(iField));
			}

			Statistics_Add(pDissolve, pLine, true);
		}
		else
		{
			Add_Line(pDissolve, pLine);

			Statistics_Add(pDissolve, pLine, false);
		}
	}

	//-----------------------------------------------------
	return( pDissolved->is_Valid() );
}
示例#10
0
//---------------------------------------------------------
bool CWKSP_Map_Graticule::Draw(CWKSP_Map_DC &dc_Map)
{
	if( !Get_Graticule(dc_Map.m_rWorld) || m_Graticule.Get_Count() <= 0 )
	{
		return( false );
	}

	if( !m_Parameters("SHOW_ALWAYS")->asBool() )
	{
		CSG_Parameter_Range	*pRange	= m_Parameters("SHOW_RANGE")->asRange();
		double	dRange	= dc_Map.m_rWorld.Get_XRange() > dc_Map.m_rWorld.Get_YRange() ? dc_Map.m_rWorld.Get_XRange() : dc_Map.m_rWorld.Get_YRange();

		if( dRange < pRange->Get_LoVal() || pRange->Get_HiVal() < dRange )
		{
			return( false );
		}
	}

	//-----------------------------------------------------
	CWKSP_Map_DC	*pDC	= m_Parameters("TRANSPARENCY")->asDouble() > 0.0 ? new CWKSP_Map_DC(dc_Map.m_rWorld, dc_Map.m_rDC, dc_Map.m_Scale, SG_GET_RGB(255, 255, 255)) : NULL;
	CWKSP_Map_DC	&dc		= pDC ? *pDC : dc_Map;

	//-----------------------------------------------------
	wxPen	Pen(m_Parameters("COLOR")->asColor(), m_Parameters("SIZE")->asInt());

	switch( m_Parameters("LINE_STYLE")->asInt() )
	{
	default:
	case  0:	Pen.SetStyle(wxPENSTYLE_SOLID           );	break; // Solid style.
	case  1:	Pen.SetStyle(wxPENSTYLE_DOT             );	break; // Dotted style.
	case  2:	Pen.SetStyle(wxPENSTYLE_LONG_DASH       );	break; // Long dashed style.
	case  3:	Pen.SetStyle(wxPENSTYLE_SHORT_DASH      );	break; // Short dashed style.
	case  4:	Pen.SetStyle(wxPENSTYLE_DOT_DASH        );	break; // Dot and dash style.
	case  5:	Pen.SetStyle(wxPENSTYLE_BDIAGONAL_HATCH );	break; // Backward diagonal hatch.
	case  6:	Pen.SetStyle(wxPENSTYLE_CROSSDIAG_HATCH );	break; // Cross-diagonal hatch.
	case  7:	Pen.SetStyle(wxPENSTYLE_FDIAGONAL_HATCH );	break; // Forward diagonal hatch.
	case  8:	Pen.SetStyle(wxPENSTYLE_CROSS_HATCH     );	break; // Cross hatch.
	case  9:	Pen.SetStyle(wxPENSTYLE_HORIZONTAL_HATCH);	break; // Horizontal hatch.
	case 10:	Pen.SetStyle(wxPENSTYLE_VERTICAL_HATCH  );	break; // Vertical hatch.
//	case 11:	Pen.SetStyle(wxPENSTYLE_STIPPLE         );	break; // Use the stipple bitmap. 
//	case 12:	Pen.SetStyle(wxPENSTYLE_USER_DASH       );	break; // Use the user dashes: see wxPen::SetDashes.
//	case 13:	Pen.SetStyle(wxPENSTYLE_TRANSPARENT     );	break; // No pen is used.
	}

	dc.dc.SetPen(Pen);

	//-----------------------------------------------------
	for(int iLine=0; iLine<m_Graticule.Get_Count(); iLine++)
	{
		CSG_Shape	*pLine	= m_Graticule.Get_Shape(iLine);

		for(int iPart=0; iPart<pLine->Get_Part_Count(); iPart++)
		{
			if( pLine->Get_Point_Count(iPart) > 1 )
			{
				TSG_Point_Int	B, A	= dc.World2DC(pLine->Get_Point(0, iPart));

				for(int iPoint=1; iPoint<pLine->Get_Point_Count(iPart); iPoint++)
				{
					B		= A;
					A		= dc.World2DC(pLine->Get_Point(iPoint, iPart));

					dc.dc.DrawLine(A.x, A.y, B.x, B.y);
				}
			}
		}
	}

	//-----------------------------------------------------
	if( m_Parameters("LABEL")->asBool() )
	{
		int	Size	= (int)(0.5 + 0.01 * m_Parameters("LABEL_SIZE")->asDouble()
		*	( dc.m_rDC.GetWidth() < dc.m_rDC.GetHeight()
			? dc.m_rDC.GetWidth() : dc.m_rDC.GetHeight() )
		);

		if( Size > 2 )
		{
			int			Effect;
			wxColour	Effect_Color	= Get_Color_asWX(m_Parameters("LABEL_EFFCOL")->asInt());
			wxFont		Font	= Get_Font(m_Parameters("LABEL_FONT"));

			Font.SetPointSize(Size);

			dc.dc.SetFont(Font);
			dc.dc.SetTextForeground(m_Parameters("LABEL_FONT")->asColor());

			switch( m_Parameters("LABEL_EFFECT")->asInt() )
			{
			default:	Effect	= TEXTEFFECT_NONE;			break;
			case 1:		Effect	= TEXTEFFECT_FRAME;			break;
			case 2:		Effect	= TEXTEFFECT_TOP;			break;
			case 3:		Effect	= TEXTEFFECT_TOPLEFT;		break;
			case 4:		Effect	= TEXTEFFECT_LEFT;			break;
			case 5:		Effect	= TEXTEFFECT_BOTTOMLEFT;	break;
			case 6:		Effect	= TEXTEFFECT_BOTTOM;		break;
			case 7:		Effect	= TEXTEFFECT_BOTTOMRIGHT;	break;
			case 8:		Effect	= TEXTEFFECT_RIGHT;			break;
			case 9:		Effect	= TEXTEFFECT_TOPRIGHT;		break;
			}

			for(int iPoint=0; iPoint<m_Coordinates.Get_Count(); iPoint++)
			{
				CSG_Shape	*pPoint	= m_Coordinates.Get_Shape(iPoint);

				TSG_Point_Int	p(dc.World2DC(pPoint->Get_Point(0)));
				wxString		Type(pPoint->asString(0));

				int	Align	= !Type.Cmp("LAT_MIN") ? TEXTALIGN_CENTERLEFT
							: !Type.Cmp("LAT_MAX") ? TEXTALIGN_CENTERRIGHT
							: !Type.Cmp("LON_MIN") ? TEXTALIGN_BOTTOMCENTER
							: !Type.Cmp("LON_MAX") ? TEXTALIGN_TOPCENTER
							: TEXTALIGN_CENTER;

				Draw_Text(dc.dc, Align, p.x, p.y, 0.0, pPoint->asString(1), Effect, Effect_Color);
			}
		}
	}

	//-----------------------------------------------------
	if( pDC )
	{
		dc_Map.Draw_DC(dc, m_Parameters("TRANSPARENCY")->asDouble() / 100.0);

		delete(pDC);
	}

	return( true );
}
示例#11
0
//---------------------------------------------------------
CSG_Shape * CSG_PointCloud::_Set_Shape(int iPoint)
{
    SG_UI_Progress_Lock(true);

    CSG_Shape	*pShape	= m_Shapes.Get_Shape(0);

    if( pShape->is_Modified() && m_Shapes_Index >= 0 && m_Shapes_Index < Get_Count() )
    {
        m_Cursor	= m_Points[m_Shapes_Index];

        for(int i=0; i<Get_Field_Count(); i++)
        {
            switch( Get_Field_Type(i) )
            {
            default:
                Set_Value(i, pShape->asDouble(i));
                break;

            case SG_DATATYPE_Date:
            case SG_DATATYPE_String:
                Set_Value(i, pShape->asString(i));
                break;
            }
        }

        Set_Value(0, pShape->Get_Point(0).x);
        Set_Value(1, pShape->Get_Point(0).y);
        Set_Value(2, pShape->Get_Z    (0)  );
    }

    if( iPoint >= 0 && iPoint < Get_Count() )
    {
        if(1|| iPoint != m_Shapes_Index )
        {
            m_Cursor	= m_Points[iPoint];

            pShape->Set_Point(Get_X(), Get_Y(), 0, 0);
            pShape->Set_Z    (Get_Z()         , 0, 0);

            for(int i=0; i<Get_Field_Count(); i++)
            {
                switch( Get_Field_Type(i) )
                {
                default:
                    pShape->Set_Value(i, Get_Value(i));
                    break;

                case SG_DATATYPE_Date:
                case SG_DATATYPE_String:
                {
                    CSG_String	s;

                    Get_Value(i, s);

                    pShape->Set_Value(i, s);
                }
                break;
                }
            }

            m_Shapes_Index	= iPoint;
            pShape->m_Index	= iPoint;
            pShape->Set_Selected(is_Selected(iPoint));
        }

        m_Shapes.Set_Modified(false);

        SG_UI_Progress_Lock(false);

        return( pShape );
    }

    m_Shapes_Index	= -1;

    SG_UI_Progress_Lock(false);

    return( NULL );
}
示例#12
0
//---------------------------------------------------------
bool CXYZ_Export::On_Execute(void)
{
	bool		bHeader;
	int			Field, off_Field, Separate;
	CSG_File	Stream;
	CSG_Shapes	*pPoints;

	//-----------------------------------------------------
	pPoints		= Parameters("POINTS"  )->asShapes();
	bHeader		= Parameters("HEADER"  )->asBool();
	Field		= Parameters("FIELD"   )->asInt();
	Separate	= pPoints->Get_Type() == SHAPE_TYPE_Point ? 0
				: Parameters("SEPARATE")->asInt();
	off_Field	= pPoints->Get_ObjectType() == SG_DATAOBJECT_TYPE_PointCloud ? 2 : 0;

	//-----------------------------------------------------
	if( pPoints->Get_Field_Count() == 0 )
	{
		Error_Set(_TL("data set has no attributes"));

		return( false );
	}

	//-----------------------------------------------------
	if( !Stream.Open(Parameters("FILENAME")->asString(), SG_FILE_W, false) )
	{
		Error_Set(_TL("could not open file"));

		return( false );
	}

	//-----------------------------------------------------
	if( bHeader )
	{
		Stream.Printf("X\tY");

		if( Field < 0 )
		{
			for(int iField=off_Field; iField<pPoints->Get_Field_Count(); iField++)
			{
				Stream.Printf("\t%s", pPoints->Get_Field_Name(iField));
			}
		}
		else
		{
			Stream.Printf("\tZ");
		}

		Stream.Printf("\n");
	}

	//-------------------------------------------------
	for(int iShape=0; iShape<pPoints->Get_Count() && Set_Progress(iShape, pPoints->Get_Count()); iShape++)
	{
		CSG_Shape	*pShape	= pPoints->Get_Shape(iShape);

		for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
		{
			switch( Separate )
			{
			case 1:	// *
				Stream.Printf("*\n");
				break;

			case 2:	// number of points
				Stream.Printf("%d\n", pShape->Get_Point_Count(iPart));
				break;
			}

			for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
			{
				TSG_Point	Point	= pShape->Get_Point(iPoint, iPart);

				Stream.Printf("%f\t%f", Point.x, Point.y);

				if( Field < 0 )
				{
					for(int iField=off_Field; iField<pPoints->Get_Field_Count(); iField++)
					{
						switch( pPoints->Get_Field_Type(iField) )
						{
						case SG_DATATYPE_String:
						case SG_DATATYPE_Date:
							Stream.Printf("\t\"%s\"", pShape->asString(iField));
							break;

						default:
							Stream.Printf("\t%f"    , pShape->asDouble(iField));
							break;
						}
					}
				}
				else switch( pPoints->Get_Field_Type(Field) )
				{
				case SG_DATATYPE_String:
				case SG_DATATYPE_Date:
					Stream.Printf("\t\"%s\"", pShape->asString(Field));
					break;

				default:
					Stream.Printf("\t%f"    , pShape->asDouble(Field));
					break;
				}

				Stream.Printf("\n");
			}
		}
	}

	//-------------------------------------------------
	return( true );
}
示例#13
0
//---------------------------------------------------------
bool CPGIS_Shapes_Save::On_Execute(void)
{
	int			SRID;
	CSG_Shapes	*pShapes;
	CSG_String	SQL, Geo_Table, Geo_Type, Geo_Field, sSRID;

	pShapes		= Parameters("SHAPES")	->asShapes();
	Geo_Table	= Parameters("NAME")	->asString();	if( Geo_Table.Length() == 0 )	Geo_Table	= pShapes->Get_Name();
	SRID		= Parameters("SRID")	->asInt();
	SRID		= SG_Get_Projections().Get_SRID_byNamesIndex(SRID);

	sSRID.Printf(SG_T("%d"), SRID);

	//-----------------------------------------------------
	switch( pShapes->Get_Vertex_Type() )
	{
	case SG_VERTEX_TYPE_XY:
		switch( pShapes->Get_Type() )
		{	default:	return( false );
		case SHAPE_TYPE_Point:		Geo_Type	= SG_OGIS_TYPE_STR_Point;			Geo_Field	= SG_T("geo_point");		break;
		case SHAPE_TYPE_Points:		Geo_Type	= SG_OGIS_TYPE_STR_MultiPoint;		Geo_Field	= SG_T("geo_points");		break;
		case SHAPE_TYPE_Line:		Geo_Type	= SG_OGIS_TYPE_STR_MultiLine;		Geo_Field	= SG_T("geo_line");			break;
		case SHAPE_TYPE_Polygon:	Geo_Type	= SG_OGIS_TYPE_STR_MultiPolygon;	Geo_Field	= SG_T("geo_polygon");		break;
		}
		break;

	case SG_VERTEX_TYPE_XYZ:
		switch( pShapes->Get_Type() )
		{	default:	return( false );
		case SHAPE_TYPE_Point:		Geo_Type	= SG_OGIS_TYPE_STR_Point_Z;			Geo_Field	= SG_T("geo_point_z");		break;
		case SHAPE_TYPE_Points:		Geo_Type	= SG_OGIS_TYPE_STR_MultiPoint_Z;	Geo_Field	= SG_T("geo_points_z");		break;
		case SHAPE_TYPE_Line:		Geo_Type	= SG_OGIS_TYPE_STR_MultiLine_Z;		Geo_Field	= SG_T("geo_line_z");		break;
		case SHAPE_TYPE_Polygon:	Geo_Type	= SG_OGIS_TYPE_STR_MultiPolygon_Z;	Geo_Field	= SG_T("geo_polygon_z");	break;
		}
		break;

	case SG_VERTEX_TYPE_XYZM:
		switch( pShapes->Get_Type() )
		{	default:	return( false );
		case SHAPE_TYPE_Point:		Geo_Type	= SG_OGIS_TYPE_STR_Point_ZM;		Geo_Field	= SG_T("geo_point_zm");		break;
		case SHAPE_TYPE_Points:		Geo_Type	= SG_OGIS_TYPE_STR_MultiPoint_ZM;	Geo_Field	= SG_T("geo_points_zm");	break;
		case SHAPE_TYPE_Line:		Geo_Type	= SG_OGIS_TYPE_STR_MultiLine_ZM;	Geo_Field	= SG_T("geo_line_zm");		break;
		case SHAPE_TYPE_Polygon:	Geo_Type	= SG_OGIS_TYPE_STR_MultiPolygon_ZM;	Geo_Field	= SG_T("geo_polygon_zm");	break;
		}
		break;
	}

	//-----------------------------------------------------
	if( Get_Connection()->Table_Exists(Geo_Table) )
	{
		Message_Add(CSG_String::Format(SG_T("%s: %s"), _TL("table already exists"), Geo_Table.c_str()));

		switch( Parameters("EXISTS")->asInt() )
		{
		case 0:	// abort export
			return( false );

		case 1:	// replace existing table
			Message_Add(CSG_String::Format(SG_T("%s: %s"), _TL("trying to drop table"), Geo_Table.c_str()));

			if( !Get_Connection()->Table_Drop(Geo_Table, false) )
			{
				Message_Add(CSG_String::Format(SG_T(" ...%s!"), _TL("failed")));

				return( false );
			}

			break;

		case 2:	// append records, if table structure allows
			break;
		}
	}

	//-----------------------------------------------------
	if( !Get_Connection()->Table_Exists(Geo_Table) && !Get_Connection()->Table_Create(Geo_Table, *pShapes, Get_Constraints(Parameters("FLAGS")->asParameters(), pShapes), false) )
	{
		Get_Connection()->Rollback();

		return( false );
	}

	//-----------------------------------------------------
	SQL.Printf(SG_T("SELECT AddGeometryColumn('%s', '%s', %d, '%s', %d)"),
		Geo_Table.c_str(),				// <table_name>
		Geo_Field.c_str(),				// <column_name>
		SRID,							// <srid>
		Geo_Type.Make_Upper().c_str(),	// <type>
		2								// <dimension>
	);

	if( !Get_Connection()->Execute(SQL) )
	{
		Get_Connection()->Rollback();

		Message_Add(_TL("could not create geometry field"));

		return( false );
	}

	//-----------------------------------------------------
	int			iShape, iField, nAdded;
	CSG_String	Insert, Fields, sWKT;

	Fields	= Geo_Field;

	for(iField=0; iField<pShapes->Get_Field_Count(); iField++)
	{
		Fields	+= CSG_String(", ") + pShapes->Get_Field_Name(iField);
	}

	Insert.Printf(SG_T("INSERT INTO %s (%s) VALUES ("), Geo_Table.c_str(), Fields.c_str());

	for(iShape=0, nAdded=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
	{
		CSG_Shape	*pShape	= pShapes->Get_Shape(iShape);

		if( pShape->is_Valid() )
		{
			SQL	= Insert;

			CSG_Shapes_OGIS_Converter::to_WKText(pShape, sWKT);

			SQL	+= SG_T("GeomFromText('") + sWKT + SG_T("', ") + sSRID + SG_T(")");

			for(iField=0; iField<pShapes->Get_Field_Count(); iField++)
			{
				CSG_String	s = pShape->asString(iField);

				if( pShapes->Get_Field_Type(iField) == SG_DATATYPE_String )
				{
					s.Replace(SG_T("'"), SG_T("\""));
					s	= SG_T("'") + s + SG_T("'");
				}

				SQL	+= SG_T(", ")  + s;
			}

			SQL	+= SG_T(")");

			if( Get_Connection()->Execute(SQL) )
			{
				nAdded++;
			}
			else
			{
				Message_Add(CSG_String::Format(SG_T("dropped %d. shape"), iShape));
			}
		}
	}

	//-----------------------------------------------------
	if( nAdded == 0 )
	{
		Get_Connection()->Rollback();

		Get_Connection()->Table_Drop(Geo_Table);

		return( false );
	}

	return( Get_Connection()->Commit() );
}
示例#14
0
//---------------------------------------------------------
bool CShapes_Save::On_Execute(void)
{
	if( !Get_Connection()->has_PostGIS() )
	{
		Error_Set(_TL("not a valid PostGIS database!"));

		return( false );
	}

	//-----------------------------------------------------
	CSG_Shapes	*pShapes;
	CSG_String	SQL, Name, Type, Field, SavePoint;

	pShapes		= Parameters("SHAPES")->asShapes();
	Name		= Parameters("NAME"  )->asString();	if( Name.Length() == 0 )	Name	= pShapes->Get_Name();

	Field		= "geometry";

	int	SRID	= Get_SRID();

	//-----------------------------------------------------
	if( !CSG_Shapes_OGIS_Converter::from_ShapeType(Type, pShapes->Get_Type(), pShapes->Get_Vertex_Type()) )
	{
		Error_Set(_TL("invalid or unsupported shape or vertex type"));

		return( false );
	}

	//-----------------------------------------------------
	Get_Connection()->Begin(SavePoint = Get_Connection()->is_Transaction() ? "SHAPES_SAVE" : "");

	//-----------------------------------------------------
	if( Get_Connection()->Table_Exists(Name) )
	{
		Message_Add(_TL("table already exists") + CSG_String(": ") + Name);

		switch( Parameters("EXISTS")->asInt() )
		{
		case 0:	// abort export
			return( false );

		case 1:	// replace existing table
			Message_Add(_TL("trying to drop table") + CSG_String(": ") + Name);

			if( !Get_Connection()->Table_Drop(Name, false) )
			{
				Message_Add(CSG_String(" ...") + _TL("failed") + "!");

				return( false );
			}

			break;

		case 2:	// append records, if table structure allows
			break;
		}
	}

	//-----------------------------------------------------
	if( !Get_Connection()->Table_Exists(Name) )
	{
		if( !Get_Connection()->Table_Create(Name, *pShapes, Get_Constraints(&Parameters, "SHAPES"), false) )
		{
			Error_Set(_TL("could not create table"));

			Get_Connection()->Rollback(SavePoint);

			return( false );
		}

		//-------------------------------------------------
		// SELECT AddGeometryColumn(<table_name>, <column_name>, <srid>, <type>, <dimension>)

		SQL.Printf(SG_T("SELECT AddGeometryColumn('%s', '%s', %d, '%s', %d)"),
			Name.c_str(), Field.c_str(), SRID, Type.c_str(),
			pShapes->Get_Vertex_Type() == SG_VERTEX_TYPE_XY  ? 2 :
			pShapes->Get_Vertex_Type() == SG_VERTEX_TYPE_XYZ ? 3 : 4
		);

		if( !Get_Connection()->Execute(SQL) )
		{
			Error_Set(_TL("could not create geometry field"));

			Get_Connection()->Rollback(SavePoint);

			return( false );
		}
	}

	//-----------------------------------------------------
	bool	bBinary	= Get_Connection()->has_Version(9);

	int		iShape, iField, nAdded;

	CSG_String	Insert	= "INSERT INTO \"" + Name + "\" (" + Field;

	for(iField=0; iField<pShapes->Get_Field_Count(); iField++)
	{
		Insert	+= CSG_String(", ") + pShapes->Get_Field_Name(iField);
	}

	Insert	+= ") VALUES (";

	//-----------------------------------------------------
	for(iShape=0, nAdded=0; iShape==nAdded && iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
	{
		CSG_Shape	*pShape	= pShapes->Get_Shape(iShape);

		if( pShape->is_Valid() )
		{
			SQL	= Insert;

			if( bBinary )
			{
				CSG_Bytes	WKB;

				CSG_Shapes_OGIS_Converter::to_WKBinary(pShape, WKB);

				SQL	+= "ST_GeomFromWKB(E'\\\\x" + WKB.toHexString() + CSG_String::Format("', %d)", SRID);
			}
			else
			{
				CSG_String	WKT;

				CSG_Shapes_OGIS_Converter::to_WKText(pShape, WKT);

				SQL	+= "ST_GeomFromText('" + WKT + CSG_String::Format("', %d)", SRID);
			}

			for(iField=0; iField<pShapes->Get_Field_Count(); iField++)
			{
				CSG_String	s = pShape->asString(iField);

				if( pShapes->Get_Field_Type(iField) == SG_DATATYPE_String )
				{
					if( 1 )
					{
						char	*_s	= NULL; if( s.to_ASCII(&_s) ) s = _s; SG_FREE_SAFE(_s);
					}

					s.Replace("'", "\"");

					s	= "'" + s + "'";
				}

				SQL	+= ", "  + s;
			}

			SQL	+= ")";

			if( Get_Connection()->Execute(SQL) )
			{
				nAdded++;
			}
			else
			{
				Message_Add(CSG_String::Format("%s [%d/%d]", _TL("could not save shape"), 1 + iShape, pShapes->Get_Count()));
			}
		}
	}

	//-----------------------------------------------------
	if( nAdded < pShapes->Get_Count() )
	{
		Message_Add(SQL);

		Get_Connection()->Rollback(SavePoint);

		return( false );
	}

	Get_Connection()->Commit(SavePoint);

	Get_Connection()->GUI_Update();

	Get_Connection()->Add_MetaData(*pShapes, Name);

	pShapes->Set_Modified(false);

	return( true );
}
示例#15
0
//---------------------------------------------------------
bool CSearchInTable::On_Execute(void)
{
	bool		*WasSelected;
	int			i, iMethod;
	CSG_String	sExpression;
	CSG_Shapes	*pShapes;

	pShapes		= Parameters("SHAPES")		->asShapes();
	sExpression	= Parameters("EXPRESSION")	->asString();
	iMethod		= Parameters("METHOD")		->asInt();

	//-----------------------------------------------------
	if( iMethod == METHOD_SELECT_FROM_SEL )
	{
		WasSelected	= new bool[pShapes->Get_Count()];

		for(i=0; i<pShapes->Get_Count() && Set_Progress(i, pShapes->Get_Count()); i++)
		{
			WasSelected[i]	= pShapes->Get_Record(i)->is_Selected();
		}
	}

	if( iMethod != METHOD_ADD_TO_SEL )
	{
		pShapes->Select();
	}

	//-----------------------------------------------------
	std::vector <int> m_Selection;

	for(i=0; i<pShapes->Get_Count() && Set_Progress(i, pShapes->Get_Count()); i++)
	{
		CSG_Shape	*pShape	= pShapes->Get_Shape(i);

		for(int j=0; j<pShapes->Get_Field_Count(); j++)
		{
			CSG_String	sValue	= pShape->asString(j);

			if( sValue.Find(sExpression) != -1 )
			{
				m_Selection.push_back(i);
				break;
			}
		}
	}

	//-----------------------------------------------------
	for(i=0; i<m_Selection.size() && Set_Progress(i, m_Selection.size()); i++)
	{
		int	iSelection = m_Selection[i];

		if( !pShapes->Get_Record(iSelection)->is_Selected() )
		{
			if( iMethod != METHOD_SELECT_FROM_SEL || WasSelected[iSelection] )
			{
				((CSG_Table *)pShapes)->Select(iSelection, true);
			}
		}
	}

	//-----------------------------------------------------
	if( iMethod == METHOD_SELECT_FROM_SEL )
	{
		delete(WasSelected);
	}

	Message_Add(CSG_String::Format(SG_T("%s: %d"), _TL("selected shapes"), m_Selection.size()));

	DataObject_Update(pShapes);

	return( true );
}
示例#16
0
//---------------------------------------------------------
bool CAtlas_BNA_Export::On_Execute(void)
{
	int			iShape, iPart, iPoint, iName1, iName2;
	FILE		*Stream;
	TSG_Point	p;
	CSG_Points	Pts;
	CSG_Shape	*pShape;
	CSG_Shapes	*pShapes;
	CSG_String	fName;

	//-----------------------------------------------------
	pShapes	= Parameters("SHAPES")	->asShapes();
	fName	= Parameters("FILE")	->asString();

	iName1	= Parameters("PNAME")	->asInt();
	iName2	= Parameters("SNAME")	->asInt();

	//-----------------------------------------------------
	if( (Stream = fopen(fName.b_str(), "w")) != NULL )
	{
		for(iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
		{
			pShape	= pShapes->Get_Shape(iShape);

			switch( pShapes->Get_Type() )
			{
			default:
				break;

			//---------------------------------------------
			case SHAPE_TYPE_Point:
				fprintf(Stream, "\"%s\",\"%s\",%d\n",
					pShape->asString(iName1),
					pShape->asString(iName2),
					1
				);

				p	= pShape->Get_Point(0);
				fprintf(Stream, "%f,%f\n", p.x, p.y);
				break;

			//---------------------------------------------
			case SHAPE_TYPE_Line:
				for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
				{
					fprintf(Stream, "\"%s\",\"%s\",%d\n",
						pShape->asString(iName1),
						pShape->asString(iName2),
						-pShape->Get_Point_Count(iPart)
					);

					for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
					{
						p	= pShape->Get_Point(iPoint, iPart);
						fprintf(Stream, "%f,%f\n", p.x, p.y);
					}
				}
				break;

			//---------------------------------------------
			case SHAPE_TYPE_Polygon:
				if( pShape->Get_Part_Count() > 0 && pShape->Get_Point_Count(0) > 2 )
				{
					Pts.Clear();

					for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
					{
						for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
						{
							Pts.Add(pShape->Get_Point(iPoint, iPart));
						}

						if( iPart > 0 )
						{
							Pts.Add(pShape->Get_Point(0, 0));
						}
					}

					if( Pts.Get_Count() > 2 )
					{
						fprintf(Stream, "\"%s\",\"%s\",%d\n",
							pShape->asString(iName1),
							pShape->asString(iName2),
							Pts.Get_Count()
						);

						for(iPoint=0; iPoint<Pts.Get_Count(); iPoint++)
						{
							fprintf(Stream, "%f,%f\n", Pts[iPoint].x, Pts[iPoint].y);
						}
					}
				}
				break;
			}
		}

		fclose(Stream);

		return( true );
	}

	//-----------------------------------------------------
	return( false );
}