private void InsertRedlineGeometry(MgGeometry geom) { MgPropertyCollection feature = new MgPropertyCollection(); MgByteReader agf = _agfRW.Write(geom); MgGeometryProperty geomProp = new MgGeometryProperty("Geometry", agf); feature.Add(geomProp); _redlineLayer.ForceRefresh(); var reader = _redlineLayer.InsertFeatures(feature); int inserted = 0; while (reader.ReadNext()) { inserted++; } reader.Close(); if (inserted > 0) { _viewer.RefreshMap(); IMapLegend legend = Shell.Instance.Legend; if (legend != null) { legend.RefreshLegend(); } } }
public void Execute(IPlatformFactory factory, ITestLogger logger) { string tmp = Path.GetTempFileName(); try { File.WriteAllText(tmp, "Hello World"); MgByteSource bs = new MgByteSource(tmp); MgByteReader reader = bs.GetReader(); MgGeometryProperty gp = new MgGeometryProperty("GeomPropName", reader); MgByteSource bs2 = new MgByteSource("../../TestData/DrawingService/SpaceShip.dwf"); MgByteReader reader2 = bs2.GetReader(); gp.Value = reader2; Assert.AreEqual(reader2.GetLength(), gp.Value.GetLength()); Assert.AreEqual(MgPropertyType.Geometry, gp.PropertyType); } finally { try { File.Delete(tmp); } catch { } } }
public static void AddPointFeature(string FeatureName, MgPropertyCollection featureProps, MgPoint geom, MgFeatureService featureSrvc, MgResourceIdentifier dataSourceId) { MgByteReader geomReader = new MgAgfReaderWriter().Write(geom); MgGeometryProperty geometryProp = new MgGeometryProperty("GEOM", geomReader); featureProps.Add(geometryProp); MgInsertFeatures cmd = new MgInsertFeatures(FeatureName, featureProps); MgFeatureCommandCollection commands = new MgFeatureCommandCollection(); commands.Add(cmd); ReleaseReader(featureSrvc.UpdateFeatures(dataSourceId, commands, false)); }
public static void AddFeatureToCollection(MgBatchPropertyCollection propCollection, MgAgfReaderWriter agfRW, int featureId, MgGeometry featureGeom) { MgPropertyCollection bufferProps = new MgPropertyCollection(); MgInt32Property idProp = new MgInt32Property("ID", featureId); //NOXLATE bufferProps.Add(idProp); MgByteReader geomReader = agfRW.Write(featureGeom); MgGeometryProperty geomProp = new MgGeometryProperty("GEOM", geomReader); //NOXLATE bufferProps.Add(geomProp); propCollection.Add(bufferProps); }
MgPropertyCollection MakePoint(String name, double x, double y, MgWktReaderWriter wktReaderWriter, MgAgfReaderWriter agfReaderWriter) { MgPropertyCollection propertyCollection = new MgPropertyCollection(); MgStringProperty nameProperty = new MgStringProperty("NAME", name); propertyCollection.Add(nameProperty); MgGeometry geometry = wktReaderWriter.Read("POINT XY (" + x + " " + y + ")"); MgByteReader geometryByteReader = agfReaderWriter.Write(geometry); MgGeometryProperty geometryProperty = new MgGeometryProperty("GEOM", geometryByteReader); propertyCollection.Add(geometryProperty); return(propertyCollection); }
private void OnPointDrawn(double x, double y) { if (_pointLayer == null) //Our point layer doesn't exist { CreateRedlineLayer(); } //Now insert our point. This code should look familiar //to you, setting up the MgPropertyCollection for insertion MgPropertyCollection props = new MgPropertyCollection(); MgWktReaderWriter wktRw = new MgWktReaderWriter(); MgAgfReaderWriter agfRw = new MgAgfReaderWriter(); MgGeometry geom = wktRw.Read("POINT (" + x + " " + y + ")"); MgByteReader agf = agfRw.Write(geom); MgGeometryProperty geomProp = new MgGeometryProperty("Geometry", agf); props.Add(geomProp); //Here's where we differ from the official MapGuide API //instead of a monolithic UpdateFeatures() that tries to //do everything, we have individual InsertFeatures/DeleteFeatures/UpdateFeatures //methods. So here's the mg-desktop way MgFeatureReader result = _pointLayer.InsertFeatures(props); result.Close(); //Or if you have have access to the MgdLayer instance /* * MgResourceIdentifier fsId = new MgResourceIdentifier(_pointLayer.GetFeatureSourceId()); * MgServiceFactory factory = new MgServiceFactory(); * MgdFeatureService featSvc = (MgdFeatureService)factory.CreateService(MgServiceType.FeatureService); * MgFeatureReader fr = featSvc.InsertFeatures(fsId, "Default:Redline", props); * fr.Close(); */ //Now refresh to see your newly drawn point mgMapViewer1.RefreshMap(); }
private void InsertRedlineGeometry(MgGeometry geom) { MgPropertyCollection feature = new MgPropertyCollection(); MgByteReader agf = _agfRW.Write(geom); MgGeometryProperty geomProp = new MgGeometryProperty("Geometry", agf); feature.Add(geomProp); _redlineLayer.ForceRefresh(); var reader = _redlineLayer.InsertFeatures(feature); int inserted = 0; while (reader.ReadNext()) { inserted++; } reader.Close(); if (inserted > 0) { _viewer.RefreshMap(); IMapLegend legend = Shell.Instance.Legend; if (legend != null) legend.RefreshLegend(); } }
private void InsertRedlineGeometry(string text, MgGeometry geom, RedlineAction onRedlineAdded) { MgPropertyCollection feature = new MgPropertyCollection(); MgByteReader agf = _agfRW.Write(geom); MgGeometryProperty geomProp = new MgGeometryProperty(RedlineSchemaFactory.GEOM_NAME, agf); feature.Add(geomProp); MgStringProperty strProp = new MgStringProperty(RedlineSchemaFactory.TEXT_NAME, text); feature.Add(strProp); MgMapBase map = _viewer.GetMap(); MgLayerCollection layers = map.GetLayers(); MgLayerBase redlineLayer = layers.GetItem(_layer.SystemName); MgClassDefinition cls = redlineLayer.GetClassDefinition(); MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties(); MgPropertyDefinition idProp = idProps.GetItem(0); redlineLayer.ForceRefresh(); //This lib doesn't reference mg-desktop so the convenience APIs aren't available to us //Gotta go the old verbose route MgFeatureCommandCollection commands = new MgFeatureCommandCollection(); MgInsertFeatures insert = new MgInsertFeatures(redlineLayer.FeatureClassName, feature); commands.Add(insert); MgPropertyCollection result = redlineLayer.UpdateFeatures(commands); //Insert result is a MgFeatureProperty containing an MgFeatureReader MgFeatureProperty insertResult = result.GetItem(0) as MgFeatureProperty; MgStringProperty errorResult = result.GetItem(0) as MgStringProperty; if (insertResult != null) { var reader = insertResult.GetValue(); int inserted = 0; int?id = null; try { if (reader.ReadNext()) { inserted++; id = reader.GetInt32(idProp.Name); } } catch (MgException ex) { ex.Dispose(); } finally { reader.Close(); } if (inserted > 0) { _viewer.RefreshMap(); onRedlineAdded(id, text); } } else if (errorResult != null) { throw new Exception(errorResult.GetValue()); } }
public void CreateNew(int uid, string infrastructureType) { if (!string.IsNullOrEmpty(infrastructureType) && (infrastructureType != "בחר מרשימה")) { SetInfrastructureType(this._parentLayer.FeatureSourceId, infrastructureType); MgGeometryProperty geometry = null; MgResourceIdentifier resId = new MgResourceIdentifier(this._parentLayer.FeatureSourceId); MgFeatureQueryOptions opt = new MgFeatureQueryOptions(); opt.SetFilter(string.Format("{0}={1}", this._uidKey, uid)); MgFeatureReader reader = this._helper.FeatureService.SelectFeatures(resId, this._parentLayer.FeatureClassName, opt); MgClassDefinition classDefinition = this._helper.FeatureService.GetClassDefinition(resId, this._parentLayer.FeatureClassName.Split(new char[] { ':' })[0], this._parentLayer.FeatureClassName.Split(new char[] { ':' })[1]); if (classDefinition != null) { string geomName = classDefinition.DefaultGeometryPropertyName; if (reader.ReadNext()) { MgByteReader value = reader.GetGeometry(geomName); if (value != null) { geometry = new MgGeometryProperty(geomName, value); } } } reader.Close(); reader.Dispose(); if (geometry != null) { MgDateTime today = new MgDateTime(); MgPropertyCollection properties = new MgPropertyCollection { geometry, new MgInt32Property("UID", uid), new MgStringProperty("InfrastructureType", infrastructureType), new MgStringProperty("OperationType", "לא מוגדר"), new MgStringProperty("Status", "פתוח"), new MgStringProperty("FeatureSource", this._parentLayer.FeatureSourceId), new MgDateTimeProperty("dtStart", today), new MgDateTimeProperty("dtDue", today), new MgDateTimeProperty("dtUpdate", today) }; MgInsertFeatures insert = new MgInsertFeatures("Maintenance", properties); MgFeatureCommandCollection commands = new MgFeatureCommandCollection { insert }; this._helper.FeatureService.UpdateFeatures(this._sdfResId, commands, false); } } }
internal static void Populate(MgPropertyCollection props, IMutableRecord record) { for (int i = 0; i < record.FieldCount; i++) { var pt = record.GetPropertyType(i); string name = record.GetName(i); if (record.IsNull(i)) { switch (pt) { case PropertyValueType.Blob: { var propVal = new MgBlobProperty(name, null); propVal.SetNull(true); props.Add(propVal); } break; case PropertyValueType.Boolean: { var propVal = new MgBooleanProperty(name, false); propVal.SetNull(true); props.Add(propVal); } break; case PropertyValueType.Byte: { var propVal = new MgByteProperty(name, 0); propVal.SetNull(true); props.Add(propVal); } break; case PropertyValueType.Clob: { var propVal = new MgClobProperty(name, null); propVal.SetNull(true); props.Add(propVal); } break; case PropertyValueType.DateTime: { var propVal = new MgDateTimeProperty(name, null); propVal.SetNull(true); props.Add(propVal); } break; case PropertyValueType.Double: { var propVal = new MgDoubleProperty(name, 0.0); propVal.SetNull(true); props.Add(propVal); } break; case PropertyValueType.Geometry: { var propVal = new MgGeometryProperty(name, null); propVal.SetNull(true); props.Add(propVal); } break; case PropertyValueType.Int16: { var propVal = new MgInt16Property(name, 0); propVal.SetNull(true); props.Add(propVal); } break; case PropertyValueType.Int32: { var propVal = new MgInt32Property(name, 0); propVal.SetNull(true); props.Add(propVal); } break; case PropertyValueType.Int64: { var propVal = new MgInt64Property(name, 0L); propVal.SetNull(true); props.Add(propVal); } break; case PropertyValueType.Single: { var propVal = new MgSingleProperty(name, 0.0f); propVal.SetNull(true); props.Add(propVal); } break; case PropertyValueType.String: { var propVal = new MgStringProperty(name, ""); propVal.SetNull(true); props.Add(propVal); } break; default: throw new NotSupportedException(); } } else { switch (pt) { case PropertyValueType.Blob: { var bytes = record.GetBlob(i); var br = new MgByteSource(bytes, bytes.Length); var bv = new MgBlobProperty(name, br.GetReader()); props.Add(bv); } break; case PropertyValueType.Boolean: { props.Add(new MgBooleanProperty(name, record.GetBoolean(i))); } break; case PropertyValueType.Byte: { props.Add(new MgByteProperty(name, record.GetByte(i))); } break; case PropertyValueType.Clob: { var bytes = record.GetBlob(i); var br = new MgByteSource(bytes, bytes.Length); var bv = new MgClobProperty(name, br.GetReader()); props.Add(bv); } break; case PropertyValueType.DateTime: { var dt = record.GetDateTime(i); var mdt = new MgDateTime((short)dt.Year, (short)dt.Month, (short)dt.Day, (short)dt.Hour, (short)dt.Minute, (short)dt.Second, dt.Millisecond * 1000); props.Add(new MgDateTimeProperty(name, mdt)); } break; case PropertyValueType.Double: { props.Add(new MgDoubleProperty(name, record.GetDouble(i))); } break; case PropertyValueType.Geometry: { MgByteReader agf = GeomConverter.GetAgf(record.GetGeometry(i)); props.Add(new MgGeometryProperty(name, agf)); } break; case PropertyValueType.Int16: { props.Add(new MgInt16Property(name, record.GetInt16(i))); } break; case PropertyValueType.Int32: { props.Add(new MgInt32Property(name, record.GetInt32(i))); } break; case PropertyValueType.Int64: { props.Add(new MgInt64Property(name, record.GetInt64(i))); } break; case PropertyValueType.Single: { props.Add(new MgSingleProperty(name, record.GetSingle(i))); } break; case PropertyValueType.String: { props.Add(new MgStringProperty(name, record.GetString(i))); } break; default: throw new NotSupportedException(); } } } }
//---------------------------------------------------------------------------------------- // �� �ܣ� ���ڴ�������ݣ�x��y�������ռ��Ҫ������ // // �� �ߣ� // // // �� �ڣ�2007.05.# // //----------------------------------------------------------------------------------------- public MgPropertyCollection MakePoint(string name, double x, double y) { MgPropertyCollection propertyCollection = new MgPropertyCollection(); MgStringProperty nameProperty = new MgStringProperty("NAME", name); propertyCollection.Add(nameProperty); MgWktReaderWriter wktReaderWriter = new MgWktReaderWriter(); MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter(); MgGeometry geometry = wktReaderWriter.Read("POINT XY (" + x.ToString() + " " + y.ToString() + ")"); MgByteReader geometryByteReader = agfReaderWriter.Write(geometry); MgGeometryProperty geometryProperty = new MgGeometryProperty("GEOM", geometryByteReader); propertyCollection.Add(geometryProperty); return propertyCollection; }
private void InsertRedlineGeometry(string text, MgGeometry geom, RedlineAction onRedlineAdded) { MgPropertyCollection feature = new MgPropertyCollection(); MgByteReader agf = _agfRW.Write(geom); MgGeometryProperty geomProp = new MgGeometryProperty(RedlineSchemaFactory.GEOM_NAME, agf); feature.Add(geomProp); MgStringProperty strProp = new MgStringProperty(RedlineSchemaFactory.TEXT_NAME, text); feature.Add(strProp); MgMapBase map = _viewer.GetMap(); MgLayerCollection layers = map.GetLayers(); MgLayerBase redlineLayer = layers.GetItem(_layer.SystemName); MgClassDefinition cls = redlineLayer.GetClassDefinition(); MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties(); MgPropertyDefinition idProp = idProps.GetItem(0); redlineLayer.ForceRefresh(); //This lib doesn't reference mg-desktop so the convenience APIs aren't available to us //Gotta go the old verbose route MgFeatureCommandCollection commands = new MgFeatureCommandCollection(); MgInsertFeatures insert = new MgInsertFeatures(redlineLayer.FeatureClassName, feature); commands.Add(insert); MgPropertyCollection result = redlineLayer.UpdateFeatures(commands); //Insert result is a MgFeatureProperty containing an MgFeatureReader MgFeatureProperty insertResult = result.GetItem(0) as MgFeatureProperty; MgStringProperty errorResult = result.GetItem(0) as MgStringProperty; if (insertResult != null) { var reader = insertResult.GetValue(); int inserted = 0; int? id = null; try { if (reader.ReadNext()) { inserted++; id = reader.GetInt32(idProp.Name); } } catch (MgException ex) { ex.Dispose(); } finally { reader.Close(); } if (inserted > 0) { _viewer.RefreshMap(); onRedlineAdded(id, text); } } else if (errorResult != null) { throw new Exception(errorResult.GetValue()); } }
private void UpdateCenterDebugPoint() { if (_debugCenter == null) _debugCenter = new MgPropertyCollection(); var center = _wktRW.Read("POINT (" + _map.ViewCenter.Coordinate.X.ToString(CultureInfo.InvariantCulture) + " " + _map.ViewCenter.Coordinate.Y.ToString(CultureInfo.InvariantCulture) + ")"); //NOXLATE var agf = _agfRW.Write(center); if (!_debugCenter.Contains("Geometry")) //NOXLATE { MgGeometryProperty geom = new MgGeometryProperty("Geometry", agf); //NOXLATE _debugCenter.Add(geom); } else { MgGeometryProperty geom = (MgGeometryProperty)_debugCenter.GetItem("Geometry"); //NOXLATE geom.SetValue(agf); } int deleted = _debugLayer.DeleteFeatures(string.Empty); Trace.TraceInformation("Deleted {0} debug points", deleted); //NOXLATE var reader = _debugLayer.InsertFeatures(_debugCenter); int inserted = 0; while (reader.ReadNext()) { inserted++; } reader.Close(); Trace.TraceInformation("Added {0} debug points", inserted); //NOXLATE _debugLayer.ForceRefresh(); }
public void GeometryProperty() { MgByteSource bs = new MgByteSource("d:/mgdev/web/src/webconfig.ini"); MgByteReader reader = bs.GetReader(); MgGeometryProperty gp = new MgGeometryProperty("GeomPropName", reader); MgByteSource bs2 = new MgByteSource("d:/MgDev/UnitTest/TestData/DrawingService/SpaceShip.dwf"); MgByteReader reader2 = bs2.GetReader(); gp.Value = reader2; Assert.AreEqual(reader2.GetLength(), gp.Value.GetLength()); Assert.AreEqual(MgPropertyType.Geometry, gp.PropertyType); }
public static void AddFeatureToCollection(MgBatchPropertyCollection propCollection, MgAgfReaderWriter agfRW, int featureId, MgGeometry featureGeom) { MgPropertyCollection bufferProps = new MgPropertyCollection(); MgInt32Property idProp = new MgInt32Property("ID", featureId); //NOXLATE bufferProps.Add(idProp); MgByteReader geomReader = agfRW.Write(featureGeom); MgGeometryProperty geomProp = new MgGeometryProperty("GEOM", geomReader); //NOXLATE bufferProps.Add(geomProp); propCollection.Add(bufferProps); }
private void OnPointDrawn(double x, double y) { if (_pointLayer == null) //Our point layer doesn't exist CreateRedlineLayer(); //Now insert our point. This code should look familiar //to you, setting up the MgPropertyCollection for insertion MgPropertyCollection props = new MgPropertyCollection(); MgWktReaderWriter wktRw = new MgWktReaderWriter(); MgAgfReaderWriter agfRw = new MgAgfReaderWriter(); MgGeometry geom = wktRw.Read("POINT (" + x + " " + y + ")"); MgByteReader agf = agfRw.Write(geom); MgGeometryProperty geomProp = new MgGeometryProperty("Geometry", agf); props.Add(geomProp); //Here's where we differ from the official MapGuide API //instead of a monolithic UpdateFeatures() that tries to //do everything, we have individual InsertFeatures/DeleteFeatures/UpdateFeatures //methods. So here's the mg-desktop way MgFeatureReader result = _pointLayer.InsertFeatures(props); result.Close(); //Or if you have have access to the MgdLayer instance /* MgResourceIdentifier fsId = new MgResourceIdentifier(_pointLayer.GetFeatureSourceId()); MgServiceFactory factory = new MgServiceFactory(); MgdFeatureService featSvc = (MgdFeatureService)factory.CreateService(MgServiceType.FeatureService); MgFeatureReader fr = featSvc.InsertFeatures(fsId, "Default:Redline", props); fr.Close(); */ //Now refresh to see your newly drawn point mgMapViewer1.RefreshMap(); }