private void TryToProjectCoord(ref Envelope fullEnvelope) { if (fullEnvelope.MinX >= -180 && fullEnvelope.MaxX <= 180 && fullEnvelope.MinY >= -90 && fullEnvelope.MaxY <= 90 && fullEnvelope.Width <= 360 && fullEnvelope.Height <= 180) { fullEnvelope = null; IProjectionTransform prj = ProjectionTransformFactory.GetDefault(); _geometries = new List <Shape>(_features.Count); foreach (Feature fet in _features) { //保留未投影前的几何形状对象 _geometries.Add(fet.Geometry.Clone() as Shape); //重投影 fet.Geometry.Project(prj); //计算外接矩形 if (fullEnvelope == null) { fullEnvelope = fet.Geometry.Envelope.Clone() as Envelope; } else { fullEnvelope.UnionWith(fet.Geometry.Envelope); } } } }
private void UpdateEnvelope() { if (_grids == null || _grids.Count == 0) { return; } int n = _grids.Count; _envelope = null; for (int i = 0; i < n; i++) { if (_grids[i].Envelope == null) { continue; } if (_envelope == null) { _envelope = _grids[i].Envelope; } _envelope.UnionWith(_grids[i].Envelope); } }
private IGrid ReadGridFromFile(int gridNo) { Envelope evp = _gridStateIndicator.GetEnvelope(gridNo); Feature[] fets = _reader.GetFeatures(evp); if (fets != null && fets.Length > 0) { fets = TrySplit(fets); if (fets == null) { return(null); } evp = fets[0].Geometry.Envelope.Clone() as Envelope; foreach (Feature fet in fets) { fet.SetFeatureClass(_featureClass); evp.UnionWith(fet.Geometry.Envelope); } return(new Grid(gridNo, evp, fets)); } return(new Grid(gridNo, evp, null)); }
public Envelope GetFullEnvelope() { if (_layerContainer == null || _layerContainer.IsEmpty()) { return(null); } Envelope evp = null; for (int i = 0; i < _layerContainer.Layers.Length; i++) { IClass fetclass = _layerContainer.Layers[i].Class as IClass; if (fetclass.IsEmpty()) { continue; } if (evp == null) { evp = fetclass.FullEnvelope.Clone() as Envelope; } evp.UnionWith(fetclass.FullEnvelope); } return(evp); }
private void CheckAndAddLevelField(out Envelope envelope) { envelope = _features[0].Geometry.Envelope.Clone() as Envelope; string fld = cstLevelField.ToUpper(); foreach (Feature fet in _features) { fet.TempFlag = false; envelope.UnionWith(fet.Geometry.Envelope); if (fet.FieldNames == null || fet.FieldNames.Length == 0) { fet.SetFieldAndValues(new string[] { fld }, new string[] { "-1" }); continue; } bool exist = false; for (int i = 0; i < fet.FieldNames.Length; i++) { if (fet.FieldNames[i].ToUpper() == fld) { fet.SetFieldValue(i, "-1"); exist = true; break; } } if (!exist) { string[] flds = new string[fet.FieldNames.Length + 1]; string[] vals = new string[fet.FieldValues.Length + 1]; Array.Copy(fet.FieldNames, flds, fet.FieldNames.Length); Array.Copy(fet.FieldValues, vals, fet.FieldValues.Length); flds[flds.Length - 1] = fld; vals[vals.Length - 1] = "-1"; fet.SetFieldAndValues(flds, vals); } } }
internal void UpdateEnvelope() { if (_features == null || _features.Count == 0) { _envelope = null; return; } _envelope = null; foreach (Feature fet in _features) { if (fet == null || fet.Geometry == null) { continue; } if (_envelope == null) { _envelope = fet.Geometry.Envelope.Clone() as Envelope; } else { _envelope.UnionWith(fet.Geometry.Envelope); } } }
private void WriteFileHeader(Feature[] features) { if (_isFirstWrite) { byte[] byteArray; Envelope env = features[0].Geometry.Envelope; for (int i = 1; i < features.Length; i++) { env.UnionWith(features[i].Geometry.Envelope); } _currentEnvelope = env; byteArray = BitConverter.GetBytes(9994); int byteArrayValue = ToLocalEndian.ToInt32FromBig(byteArray); _bwMainFile.Write(byteArrayValue); _bwShxFile.Write(byteArrayValue); byteArray = new byte[20]; _bwMainFile.Write(byteArray); _bwShxFile.Write(byteArray); // byteArray = BitConverter.GetBytes(CalculateMainfileLengthInByte(features) / 2); _bwMainFile.Write(ToLocalEndian.ToInt32FromBig(byteArray)); byteArray = BitConverter.GetBytes(CalculateShxfileLenthInByte(features) / 2); _bwShxFile.Write(ToLocalEndian.ToInt32FromBig(byteArray)); // _bwMainFile.Write(1000); _bwShxFile.Write(1000); _bwMainFile.Write((int)_shapeType); _bwShxFile.Write((int)_shapeType); byteArray = BitConverter.GetBytes(env.MinX); _bwMainFile.Write(byteArray); _bwShxFile.Write(byteArray); byteArray = BitConverter.GetBytes(env.MinY); _bwMainFile.Write(byteArray); _bwShxFile.Write(byteArray); byteArray = BitConverter.GetBytes(env.MaxX); _bwMainFile.Write(byteArray); _bwShxFile.Write(byteArray); byteArray = BitConverter.GetBytes(env.MaxY); _bwMainFile.Write(byteArray); _bwShxFile.Write(byteArray); byteArray = new byte[32]; _bwMainFile.Write(byteArray); _bwShxFile.Write(byteArray); _isFirstWrite = false; } else { byte[] byteArray; Envelope env = features[0].Geometry.Envelope; for (int i = 1; i < features.Length; i++) { env.UnionWith(features[i].Geometry.Envelope); } if (_currentEnvelope != null) { env.UnionWith(_currentEnvelope); } _currentEnvelope = env; _fsMainFile.Seek(24, SeekOrigin.Begin); _fsShxFile.Seek(24, SeekOrigin.Begin); byteArray = BitConverter.GetBytes(CalculateMainfileLengthInByte(features) / 2); _bwMainFile.Write(ToLocalEndian.ToInt32FromBig(byteArray)); byteArray = BitConverter.GetBytes(CalculateShxfileLenthInByte(features) / 2); _bwShxFile.Write(ToLocalEndian.ToInt32FromBig(byteArray)); //// _fsMainFile.Seek(8, SeekOrigin.Current); _fsShxFile.Seek(8, SeekOrigin.Current); byteArray = BitConverter.GetBytes(env.MinX); _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray)); _bwShxFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray)); byteArray = BitConverter.GetBytes(env.MinY); _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray)); _bwShxFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray)); byteArray = BitConverter.GetBytes(env.MaxX); _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray)); _bwShxFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray)); byteArray = BitConverter.GetBytes(env.MaxY); _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray)); _bwShxFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray)); } }
private void WriteVectorDataToFiles(Feature[] features) { byte[] byteArray; Envelope env = new Envelope(double.MaxValue, double.MaxValue, double.MinValue, double.MinValue); foreach (Feature vf in features) { env.UnionWith(vf.Geometry.Envelope); } ////write main file //write main file and shx file header byteArray = BitConverter.GetBytes(9994); _bwMainFile.Write(ToLocalEndian.ToInt32FromBig(byteArray)); _bwShxFile.Write(ToLocalEndian.ToInt32FromBig(byteArray)); byteArray = new byte[20]; _bwMainFile.Write(byteArray); _bwShxFile.Write(byteArray); //// byteArray = BitConverter.GetBytes(CalculateMainfileLengthInByte(features) / 2); _bwMainFile.Write(ToLocalEndian.ToInt32FromBig(byteArray)); byteArray = BitConverter.GetBytes(CalculateShxfileLenthInByte(features) / 2); _bwShxFile.Write(ToLocalEndian.ToInt32FromBig(byteArray)); //// byteArray = BitConverter.GetBytes(1000); _bwMainFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray)); _bwShxFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray)); byteArray = BitConverter.GetBytes((int)_shapeType); _bwMainFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray)); _bwShxFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray)); byteArray = BitConverter.GetBytes(env.MinX); _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray)); _bwShxFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray)); byteArray = BitConverter.GetBytes(env.MinY); _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray)); _bwShxFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray)); byteArray = BitConverter.GetBytes(env.MaxX); _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray)); _bwShxFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray)); byteArray = BitConverter.GetBytes(env.MaxY); _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray)); _bwShxFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray)); byteArray = new byte[32]; _bwMainFile.Write(byteArray); _bwShxFile.Write(byteArray); //write main file and Shx file records switch (_shapeType) { case enumShapeType.Point: WriteShapePointRecords(features); break; case enumShapeType.MultiPoint: WriteShapeMultiPointRecords(features); break; case enumShapeType.Polyline: WriteShapePolylineRecords(features); break; case enumShapeType.Polygon: WriteShapePolygonRecords(features); break; default: break; } ////write prj file,leave it now,no spec CloseVectorDataFiles(); }