//设置区划中心点和边界 private void SetRegionInfo(csGovRegion csGR) { try { //获取GIS信息 Recordset recdst2 = GetRecordsetByCode(csGR.RegionCode); if (recdst2 != null && recdst2.RecordCount > 0) { csGR.RegionCenter = new csCenter(); csGR.RegionBounds = new csBounds(); GeoLine geoLine1 = recdst2.GetGeometry() as GeoLine; csGR.RegionCenter.center = GetCenterPoint(csGR.RegionCode); double dKey = 10714896 / 111000 / 0.08; while (!recdst2.IsEOF) { try { GeoLine geoLine2 = recdst2.GetGeometry() as GeoLine; for (int i = 0; i < geoLine2.PartCount; i++) { GeoLine geoL = new GeoLine(geoLine2[i]); GeoLine geoLine = null; if (geoL[0].Count < 400) { geoLine = geoL; } else { double dTolerance = geoL.Length / dKey; { //dTolerance = GetTolerance(csGR.RegionCode); } geoLine = Geometrist.Resample(geoL, ResampleType.RTGeneral, dTolerance) as GeoLine; } csGR.RegionBounds.bounds.Add(geoLine[0].Clone()); } } catch (SystemException sysEx) { string strErr = sysEx.Message; } recdst2.MoveNext(); } } } catch {} }
//以GIS地图为主,添加到数据库中 private void WriteToDatabaseByGIS() { string strTableName = "t_busi_xzqh_bygis"; string strTableName2 = "t_gov_region"; int iIndex = 0; try { //using (conn = new OracleConnection(connString)) //先删除原来数据 { { string strSQL = string.Format("delete {0}", strTableName); DbHelperOra.ExecuteSql(DbHelperOra.connectionString_172, strSQL); } } //插入第一条数据“中国” { { string strSQL = string.Format("insert into {0}(id,qhmc,qhbm,pid,qhjb,center,viewbounds,qhpy) values('E312A4C4B6F9416283B7E4052A27C031','中国','000000','0',0,null,empty_blob(),'zhongguo')", strTableName); DbHelperOra.ExecuteSql(DbHelperOra.connectionString_172, strSQL); } } { //拿到所有区划 string strQuery = string.Format("select t.r_code,t.r_name,t.r_pcode,t.r_level from {0} t where t.r_pcode is not null order by t.r_level", strTableName2); DataSet dtSet = DbHelperOra.Query(DbHelperOra.connectionString_Local, strQuery); DataTable dtTable = dtSet.Tables[0]; foreach (DataRow dr in dtTable.Rows) { iIndex++; //获取区划代码 string strBM = string.Format("{0}", dr[0]); if (strBM.Length < 6) { continue; } string strName = string.Format("{0}", dr[1]); string strPCODE = string.Format("{0}", dr[2]); string strRLEVEL = string.Format("{0}", dr[3]); csGovRegion csGR = new csGovRegion(strName, strBM, strPCODE); SetRegionInfo(csGR); if (csGR.RegionCenter != null) { if (strBM.Length > 0) { string strGUID = Guid.NewGuid().ToString("N").ToUpper(); string strCenter = JSONHelper.ObjectToJSON(csGR.RegionCenter.center); string strPoints = JSONHelper.ObjectToJSON(csGR.RegionBounds.bounds); string strSQL = string.Format("insert into {0}(ID,QHMC,QHBM,PID,CENTER,QHJB,VIEWBOUNDS) values('{1}','{2}','{3}','{4}','{5}',{6},empty_blob())", strTableName, strGUID, strName, strBM, strPCODE, strCenter, strRLEVEL); string strROWID = DbHelperOra.ExecuteOracleSql(DbHelperOra.connectionString_172, strSQL); string strFilter = string.Format("rowid = '{0}'", strROWID); DbHelperOra.RwiteRegionBoundsBlobToTable(DbHelperOra.connectionString_172, strTableName, "VIEWBOUNDS", strFilter, strPoints); } } } MessageBox.Show("入库完毕"); } } catch (SystemException sysEx) { string strErr = sysEx.Message; } }