public FishingGroundMappingHandler(GeoProjection geoProjection = null) { _geoProjection.SetWgs84(); if (geoProjection != null) { _geoProjection = geoProjection; } }
public static void CheckProjection() { var proj = new GeoProjection { GlobalCallback = callback }; if (proj.SetWgs84()) { if (!proj.SetGoogleMercator()) { MessageBox.Show("ERROR: failed to set projection"); } else { axMap1.GeoProjection = proj; if (!proj.SetWgs84()) { Debug.WriteLine("Failed to change projection of the map; Frozen: " + proj.IsFrozen); axMap1.GeoProjection = proj.Clone(); if (!proj.SetWgs84()) { MessageBox.Show("ERROR: projection is still frozen when no longer applied to map"); } else { Debug.WriteLine("Projection changed; Frozen: " + proj.IsFrozen); MessageBox.Show("Success"); } } else { MessageBox.Show("ERROR: projection of the map was changed; Frozen: " + proj.IsFrozen); } } } else { MessageBox.Show("Failed to set WGS84 projection"); } }
public void CreateLayerSQLiteTest() { var ogrDatasource = new OgrDatasource(); try { var result = ogrDatasource.Open2(@"sqlite\onepoint.sqlite", true); Assert.IsTrue(result, "Cannot open SQLite file: " + ogrDatasource.GdalLastErrorMsg); var settings = new GlobalSettings { OgrLayerForceUpdateMode = true }; var capability = ogrDatasource.TestCapability(tkOgrDSCapability.odcCreateLayer); Debug.WriteLine("odcCreateLayer: " + capability); Assert.IsTrue(capability, "Cannot create layer"); var originalLayerCount = ogrDatasource.LayerCount; var projection = new GeoProjection(); Assert.IsTrue(projection.SetWgs84(), "Cannot set projection"); var layerCreated = ogrDatasource.CreateLayer("Test", ShpfileType.SHP_POINT, projection, "OVERWRITE=YES"); Assert.IsTrue(layerCreated, "Cannot create layer"); Debug.WriteLine(ogrDatasource.GdalLastErrorMsg); Assert.AreEqual(originalLayerCount + 1, ogrDatasource.LayerCount, "New layer isn't created"); Debug.WriteLine("GetLayerName: " + ogrDatasource.GetLayerName(ogrDatasource.LayerCount - 1)); var firstLayer = ogrDatasource.GetLayer(0); Assert.IsNotNull(firstLayer, $"Could not get first layer: {ogrDatasource.GdalLastErrorMsg}"); // Get layer: var newLayer = ogrDatasource.GetLayer(ogrDatasource.LayerCount - 1, true); // var newLayer = ogrDatasource.GetLayerByName("test", true); Assert.IsNotNull(newLayer, $"Could not get new layer: {ogrDatasource.GdalLastErrorMsg}"); // Add field: var numFeatures = newLayer.FeatureCount[true]; Debug.WriteLine("numFeatures: " + numFeatures); TestSQLiteLayers(ogrDatasource); } finally { if (ogrDatasource.LayerCount > 1) { ogrDatasource.DeleteLayer(ogrDatasource.LayerCount); } ogrDatasource.Close(); } }
private void button1_Click(object sender, EventArgs e) { if (App.Map.NumLayers > 0) { MessageHelper.Info("Can't change projection when there are layers on the map."); return; } var gp = new GeoProjection(); if (optDefinition.Checked) { if (string.IsNullOrWhiteSpace(txtDefinition.Text)) { MessageHelper.Info("Projection string is empty"); return; } if (!gp.ImportFromAutoDetect(txtDefinition.Text)) { MessageHelper.Info("Failed to identify projection"); return; } } if (optEmpty.Checked) { // do nothing it's empty all right } if (optWellKnown.Checked) { if (cboWellKnown.SelectedIndex == 0) { gp.SetWgs84(); } if (cboWellKnown.SelectedIndex == 1) { gp.SetGoogleMercator(); } } App.Map.GeoProjection = gp; App.Map.Redraw(); DialogResult = DialogResult.OK; }
/// <summary> /// add the MBR of a target area as a new map layer /// </summary> /// <param name="moveMapToMBRCenter"></param> public void AddMBRLayer(TargetArea targetArea, bool moveMapToMBRCenter = false) { var sf = new Shapefile(); if (sf.CreateNew("", ShpfileType.SHP_POLYGON)) { GeoProjection gp = new GeoProjection(); gp.SetWgs84(); sf.GeoProjection = gp; int ifldTargetArea = sf.EditAddField("Target area", FieldType.STRING_FIELD, 1, 30); int ifldyMax = sf.EditAddField("yMax", FieldType.DOUBLE_FIELD, 10, 12); int ifldxMin = sf.EditAddField("xMin", FieldType.DOUBLE_FIELD, 10, 12); int ifldyMin = sf.EditAddField("yMin", FieldType.DOUBLE_FIELD, 10, 12); int ifldxMax = sf.EditAddField("xMax", FieldType.DOUBLE_FIELD, 10, 12); int ifldWidth = sf.EditAddField("Width", FieldType.DOUBLE_FIELD, 10, 12); int ifldHeight = sf.EditAddField("Height", FieldType.DOUBLE_FIELD, 10, 12); int ifldArea = sf.EditAddField("Area", FieldType.DOUBLE_FIELD, 15, 17); var ext = new Extents(); //ext.SetBounds(FishingGrid.LowerRighttExtent.X, // FishingGrid.LowerRighttExtent.Y, // 0, // FishingGrid.UpperLeftExtent.X, // FishingGrid.UpperLeftExtent.Y, // 0); ext.SetBounds(targetArea.UpperLeftPointLL.X, targetArea.LowerRightPointLL.Y, 0, targetArea.LowerRightPointLL.X, targetArea.UpperLeftPointLL.Y, 0); var shp = ext.ToShape(); int iShp = sf.EditAddShape(shp); if (iShp >= 0) { sf.EditCellValue(ifldTargetArea, iShp, targetArea.TargetAreaName); if (sf.Labels.Generate("[Target area]", tkLabelPositioning.lpCenter, true) > 0) { sf.Labels.FontSize = 13; sf.Labels.FrameVisible = false; sf.Labels.Visible = true; sf.Labels.FontBold = true; } sf.EditCellValue(ifldyMax, iShp, ext.yMax); sf.EditCellValue(ifldxMin, iShp, ext.xMin); sf.EditCellValue(ifldyMin, iShp, ext.yMin); sf.EditCellValue(ifldxMax, iShp, ext.xMax); sf.EditCellValue(ifldWidth, iShp, targetArea.Width); sf.EditCellValue(ifldHeight, iShp, targetArea.Height); sf.EditCellValue(ifldArea, iShp, targetArea.Area); sf.DefaultDrawingOptions.FillVisible = false; sf.DefaultDrawingOptions.LineColor = new Utils().ColorByName(tkMapColor.Blue); sf.DefaultDrawingOptions.LineWidth = 2; AddLayer(sf, "MBR", true, true); if (moveMapToMBRCenter) { ext = MapControl.Extents; ext.MoveTo(sf.Extents.Center.x, sf.Extents.Center.y); MapControl.Extents = ext; } } } }
public bool SetWgs84() { _epsgCode = 4326; return(_projection.SetWgs84()); }
public bool SetWgs84() { return(_projection.SetWgs84()); }