GIS内核-查询数据集数据并保存到新数据集, 转换中做动态投影

本文介绍如何使用GsConnectProperty连接GeoDatabase,并实现从原始FeatureClass到目标FeatureClass的数据迁移及坐标转换。通过具体代码展示了如何创建新的空间索引及进行简单的坐标限制。
	GsConnectProperty conn;
	conn.Server ="C:\";
	GsSqliteGeoDatabaseFactory fac;
	GsGeoDatabasePtr ptrGDB = fac.Open(conn);

	GsFeatureClassPtr ptrFeaOri = ptrGDB->OpenFeatureClass("countries");
	GsGeometryColumnInfo col;
	col.GeometryType = eGeometryTypePolygon;
	GsSpatialReferencePtr ptrSR = new GsSpatialReference(eWebMercator);

	GsFeatureClassPtr ptrFeaTarget = ptrGDB->CreateFeatureClass("MKT",ptrFeaOri->Fields(),
				col,ptrSR);
	//原始的查询一个
	GsFeatureCursorPtr ptrCursor = ptrFeaOri->Search();

	
	GsSpatialReferencePtr ptrWGS84 = new GsSpatialReference(eWGS84);
	GsProjectCoordinateTransformationPtr proj = new GsProjectCoordinateTransformation(ptrWGS84,ptrSR);
	SimpleTrans trans(proj);
	//创建目标的feature
	GsFeaturePtr ptrFea = ptrFeaTarget->CreateFeature();
	while(ptrCursor->Next(ptrFea))
	{
		ptrFea->GeometryBlob()->Transform(&trans);


		ptrFea->OID(-1);
		ptrFea->Store();
	}
	ptrFeaTarget->CreateSpatialIndex();

class SimpleTrans:public GsCoordinateTransformation
{ 
	GsProjectCoordinateTransformationPtr m_proj;
	double m_Max;
public:
	SimpleTrans(GsProjectCoordinateTransformation *proj)
	{
		m_Max = 85.05112877980659;
		m_proj = proj;
	}
	
	/// \brief 对x数组和y数组以及Z数组分别转换
	virtual bool Transformation(double* pX,double *pY,double *pZ,int nPointCount,int nPointOff)
	{
		for(int i =0;i<nPointCount;i++)
		{
			int index = i * nPointOff;
			 if(pY[index] > m_Max)
				 pY[index] = m_Max;
			 else if(pY[index] < (-1 * m_Max))
				 pY[index] = -1 * m_Max;
		}
		m_proj->Transformation(pX,pY,pZ,nPointCount,nPointOff);
		return true;
	}

};



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值