Ejemplo n.º 1
0
 private void AddRectangle(RedlineTextFunction retrieveTextMethod, RedlineAction onRedlineAdded)
 {
     _viewer.DigitizeRectangle((x1, y1, x2, y2) =>
     {
         string text = string.Empty;
         if (retrieveTextMethod != null)
         {
             text = retrieveTextMethod();
         }
         MgGeometry geom = _wktRW.Read(Util.MakeWktPolygon(x1, y1, x2, y2));
         InsertRedlineGeometry(text, geom, onRedlineAdded);
     });
 }
Ejemplo n.º 2
0
 private void AddCircle(RedlineTextFunction retrieveTextMethod, RedlineAction onRedlineAdded)
 {
     _viewer.DigitizeCircle((x, y, r) =>
     {
         string text = string.Empty;
         if (retrieveTextMethod != null)
         {
             text = retrieveTextMethod();
         }
         MgGeometry geom = _wktRW.Read(Util.MakeWktCircle(x, y, r, true));
         InsertRedlineGeometry(text, geom, onRedlineAdded);
     });
 }
Ejemplo n.º 3
0
 private void AddPoint(RedlineTextFunction retrieveTextMethod, RedlineAction onRedlineAdded)
 {
     _viewer.DigitizePoint((x, y) =>
     {
         string text = string.Empty;
         if (retrieveTextMethod != null)
         {
             text = retrieveTextMethod();
         }
         MgCoordinate coord = _geomFact.CreateCoordinateXY(x, y);
         MgGeometry point   = _geomFact.CreatePoint(coord);
         InsertRedlineGeometry(text, point, onRedlineAdded);
     });
 }
Ejemplo n.º 4
0
 private void AddLine(RedlineTextFunction retrieveTextMethod, RedlineAction onRedlineAdded)
 {
     _viewer.DigitizeLine((x1, y1, x2, y2) =>
     {
         string text = string.Empty;
         if (retrieveTextMethod != null)
         {
             text = retrieveTextMethod();
         }
         MgCoordinateCollection coords = new MgCoordinateCollection();
         coords.Add(_geomFact.CreateCoordinateXY(x1, y1));
         coords.Add(_geomFact.CreateCoordinateXY(x2, y2));
         MgGeometry line = _geomFact.CreateLineString(coords);
         InsertRedlineGeometry(text, line, onRedlineAdded);
     });
 }
Ejemplo n.º 5
0
 private void AddLineString(RedlineTextFunction retrieveTextMethod, RedlineAction onRedlineAdded)
 {
     _viewer.DigitizeLineString((coordinates) =>
     {
         string text = string.Empty;
         if (retrieveTextMethod != null)
         {
             text = retrieveTextMethod();
         }
         MgCoordinateCollection coords = new MgCoordinateCollection();
         for (int i = 0; i < coordinates.GetLength(0); i++)
         {
             coords.Add(_geomFact.CreateCoordinateXY(coordinates[i, 0], coordinates[i, 1]));
         }
         MgGeometry line = _geomFact.CreateLineString(coords);
         InsertRedlineGeometry(text, line, onRedlineAdded);
     });
 }
Ejemplo n.º 6
0
 public void AddObject(RedlineGeometryType type, RedlineTextFunction retrieveTextMethod, RedlineAction onRedlineAdded)
 {
     switch (type)
     {
         case RedlineGeometryType.Point:
             AddPoint(retrieveTextMethod, onRedlineAdded);
             break;
         case RedlineGeometryType.Circle:
             AddCircle(retrieveTextMethod, onRedlineAdded);
             break;
         case RedlineGeometryType.Line:
             AddLine(retrieveTextMethod, onRedlineAdded);
             break;
         case RedlineGeometryType.LineString:
             AddLineString(retrieveTextMethod, onRedlineAdded);
             break;
         case RedlineGeometryType.Polygon:
             AddPolygon(retrieveTextMethod, onRedlineAdded);
             break;
         case RedlineGeometryType.Rectangle:
             AddRectangle(retrieveTextMethod, onRedlineAdded);
             break;
     }
 }
Ejemplo n.º 7
0
        public void AddObject(RedlineGeometryType type, RedlineTextFunction retrieveTextMethod, RedlineAction onRedlineAdded)
        {
            switch (type)
            {
            case RedlineGeometryType.Point:
                AddPoint(retrieveTextMethod, onRedlineAdded);
                break;

            case RedlineGeometryType.Circle:
                AddCircle(retrieveTextMethod, onRedlineAdded);
                break;

            case RedlineGeometryType.Line:
                AddLine(retrieveTextMethod, onRedlineAdded);
                break;

            case RedlineGeometryType.LineString:
                AddLineString(retrieveTextMethod, onRedlineAdded);
                break;

            case RedlineGeometryType.Polygon:
                AddPolygon(retrieveTextMethod, onRedlineAdded);
                break;

            case RedlineGeometryType.Rectangle:
                AddRectangle(retrieveTextMethod, onRedlineAdded);
                break;
            }
        }
Ejemplo n.º 8
0
        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());
            }
        }
Ejemplo n.º 9
0
 private void AddCircle(RedlineTextFunction retrieveTextMethod, RedlineAction onRedlineAdded)
 {
     _viewer.DigitizeCircle((x, y, r) =>
     {
         string text = string.Empty;
         if (retrieveTextMethod != null)
             text = retrieveTextMethod();
         MgGeometry geom = _wktRW.Read(Util.MakeWktCircle(x, y, r, true));
         InsertRedlineGeometry(text, geom, onRedlineAdded);
     });
 }
Ejemplo n.º 10
0
 private void AddPoint(RedlineTextFunction retrieveTextMethod, RedlineAction onRedlineAdded)
 {
     _viewer.DigitizePoint((x, y) =>
     {
         string text = string.Empty;
         if (retrieveTextMethod != null)
             text = retrieveTextMethod();
         MgCoordinate coord = _geomFact.CreateCoordinateXY(x, y);
         MgGeometry point = _geomFact.CreatePoint(coord);
         InsertRedlineGeometry(text, point, onRedlineAdded);
     });
 }
Ejemplo n.º 11
0
 private void AddLine(RedlineTextFunction retrieveTextMethod, RedlineAction onRedlineAdded)
 {
     _viewer.DigitizeLine((x1, y1, x2, y2) =>
     {
         string text = string.Empty;
         if (retrieveTextMethod != null)
             text = retrieveTextMethod();
         MgCoordinateCollection coords = new MgCoordinateCollection();
         coords.Add(_geomFact.CreateCoordinateXY(x1, y1));
         coords.Add(_geomFact.CreateCoordinateXY(x2, y2));
         MgGeometry line = _geomFact.CreateLineString(coords);
         InsertRedlineGeometry(text, line, onRedlineAdded);
     });
 }
Ejemplo n.º 12
0
 private void AddLineString(RedlineTextFunction retrieveTextMethod, RedlineAction onRedlineAdded)
 {
     _viewer.DigitizeLineString((coordinates) =>
     {
         string text = string.Empty;
         if (retrieveTextMethod != null)
             text = retrieveTextMethod();
         MgCoordinateCollection coords = new MgCoordinateCollection();
         for (int i = 0; i < coordinates.GetLength(0); i++)
         {
             coords.Add(_geomFact.CreateCoordinateXY(coordinates[i, 0], coordinates[i, 1]));
         }
         MgGeometry line = _geomFact.CreateLineString(coords);
         InsertRedlineGeometry(text, line, onRedlineAdded);
     });
 }
Ejemplo n.º 13
0
 private void AddRectangle(RedlineTextFunction retrieveTextMethod, RedlineAction onRedlineAdded)
 {
     _viewer.DigitizeRectangle((x1, y1, x2, y2) =>
     {
         string text = string.Empty;
         if (retrieveTextMethod != null)
             text = retrieveTextMethod();
         MgGeometry geom = _wktRW.Read(Util.MakeWktPolygon(x1, y1, x2, y2));
         InsertRedlineGeometry(text, geom, onRedlineAdded);
     });
 }
Ejemplo n.º 14
0
        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());
            }
        }