I've just started using Sharpmap but I have a problem. I'm not able to print points (not even one) over a map using this library.
I didn't find a good example to do it, and my code is not working. It draws a point way too far from where it should be (Madrid, Spain).
I would appreciate some help if someone knows how to use it.
Here is my code :
namespace TestsSharpmapForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
VectorLayer vlay = new VectorLayer("Spain");
vlay.DataSource = new SharpMap.Data.Providers.ShapeFile(#"ESP_adm_shp\ESP_adm2.shp", true);
VectorLayer vlay2 = new VectorLayer("Points");
Collection<GeoAPI.Geometries.IGeometry> geomColl = new Collection<GeoAPI.Geometries.IGeometry>();
//Get the default geometry factory
GeoAPI.GeometryServiceProvider.Instance = new NetTopologySuite.NtsGeometryServices();
GeoAPI.Geometries.IGeometryFactory gf =
GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory();
geomColl.Add(gf.CreatePoint(new GeoAPI.Geometries.Coordinate(40.4177623, -3.6690416)));
vlay2.DataSource = new SharpMap.Data.Providers.GeometryProvider(geomColl);
mapBox1.Map.Layers.Add(vlay);
mapBox1.Map.Layers.Add(vlay2);
//ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
//vlay.CoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator);
//vlay.ReverseCoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator, ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84);
mapBox1.Map.ZoomToExtents();
mapBox1.Refresh();
mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;
Image imgMap = mapBox1.Map.GetMap();
}
private void mapBox1_Click(object sender, EventArgs e)
{
}
}
}
X and Y should be the other way round:
geomColl.Add(gf.CreatePoint(new GeoAPI.Geometries.Coordinate(-3.6690416, 40.4177623)));
Related
I'm new to repository pattern/unit of work.
I used the GitHub-timschreiber DapperUnitOfWork here and adjust it to my data.
I use WinForms. First I load my Form an load all data to dataGridView. Then I want to use da textBox to filter data. Everything works well.
public Form1()
{
InitializeComponent();
Test();
}
void Test()
{
using (var uow = new UnitOfWork(AppConnection.ConnectionString))
{
dataGridView1.DataSource = uow.ProductRepository.GetAll();
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
using (var uow = new UnitOfWork(AppConnection.ConnectionString))
{
var filteredList = uow.ProductRepository.GetAll().Where(c => c.Ident.Contains(textBox1.Text)).ToList();
dataGridView1.DataSource = filteredList;
}
}
Now my question: Is this the right way to make use of it?
I mean for every action I need a using for the DB.
So is it correct or what is the right way?
I'm trying to center a map on a custom location with the following code:
mapView = new MapKit.MKMapView();
mapView.ZoomEnabled = true;
mapView.ScrollEnabled = true;
mapDelegate = new GeoFleet.iOS.MapDelegate();
mapView.Delegate = mapDelegate;
var region = new MapKit.MKCoordinateRegion(
new CLLocationCoordinate2D(latitude: 43.6114099, longitude: 7.0817283),
new MapKit.MKCoordinateSpan(0.00899321605918731, 0.0124209769840958)
);
this.mapView.Region = region;
Unfortunately, this displays me the map of France; not the country's south east location I'm requesting.
How can I debug this kind of problem?
EDIT:
You can go to the location with the following link.
I've tried this other call which does neither work:
MapKit.MKCoordinateRegion.FromDistance(new CLLocationCoordinate2D(latitude: 43.6114099, longitude: 7.0817283), 2000, 2000);
this works for me
public partial class ViewController : UIViewController
{
MKMapView map;
UIButton btn;
public ViewController(IntPtr handle) : base(handle)
{
map = new MKMapView(this.View.Bounds);
this.View.AddSubview(map);
btn = new UIButton(UIButtonType.RoundedRect);
btn.SetTitle("GO!!!",UIControlState.Normal);
btn.TouchDown += Btn_TouchDown;
btn.Frame = new CoreGraphics.CGRect(100,200,50,50);
this.View.AddSubview(btn);
}
private void Btn_TouchDown(object sender, EventArgs e)
{
this.map.Region = new MapKit.MKCoordinateRegion(
new CLLocationCoordinate2D(latitude: 43.6114099, longitude: 7.0817283),
new MapKit.MKCoordinateSpan(0.00899321605918731, 0.0124209769840958)
);
}
}
I am trying to learn GTK# (obviously in C#). I am using Ubuntu and I compile with mono. I want to create a MenuBar and add some Menu, and MenuItem to it.
When I compile, all is OK but my menu isn't displaying.
public MainWindow() : base("LayText")
{
SetDefaultSize(800, 600);
SetPosition(WindowPosition.Center);
DeleteEvent += delegate { Application.Quit(); };
this.InitializeComponent();
ShowAll();
}
private void InitializeComponent()
{
this.m_new = new MenuItem("Nouveau fichier");
this.m_open = new MenuItem("Ouvrir fichier");
this.m_exit = new MenuItem("Quitter");
this.file = new Menu();
this.file.Append(this.m_new);
this.file.Append(this.m_open);
this.file.Append(this.m_exit);
this.menu_file = new MenuItem("Fichier");
this.menu_file.Submenu = this.file;
this.menu_bar = new MenuBar();
this.menu_bar.Append(this.menu_file);
this.vbox_princ = new VBox(false, 2);
this.vbox_princ.PackStart(this.menu_bar, false, false, 0);
this.Add(this.vbox_princ);
}
When I compile this code I am getting the window but without the menu I've set.
Screenshot of the window
Thanks for helping me.
Layce17
The following code (just a modification/completion or yours) works perfectly. I see you are using Ubuntu. Though I don't use it, I think it shows the menu bar in the top status bar. Have you checked that out?
using Gtk;
namespace Kk
{
class MainWindow: Gtk.Window {
public MainWindow() : base("LayText")
{
SetDefaultSize(800, 600);
SetPosition(WindowPosition.Center);
DeleteEvent += delegate { Application.Quit(); };
this.InitializeComponent();
ShowAll();
}
private void InitializeComponent()
{
var m_new = new MenuItem("Nouveau fichier");
var m_open = new MenuItem("Ouvrir fichier");
var m_exit = new MenuItem("Quitter");
var file = new Menu();
file.Append(m_new);
file.Append(m_open);
file.Append(m_exit);
var menu_file = new MenuItem("Fichier");
menu_file.Submenu = file;
var menu_bar = new MenuBar();
menu_bar.Append(menu_file);
var vbox_princ = new VBox(false, 2);
vbox_princ.PackStart(menu_bar, false, false, 0);
this.Add(vbox_princ);
}
public static void Main()
{
Application.Init();
new MainWindow();
Application.Run();
}
}
}
Hope this helps.
I am trying to write a code in which I got as xml format for the first image api from wikipedia. Now I want to parse it through c#. But I cannot get the image while running code. here is my code.
namespace WikiAPIWinForm
{
public partial class WikiForm : Form
{
private const string url1_Image1 = "https://en.wikipedia.org/w/api.php?action=query&titles=File:Schloss%20Neuschwanstein%202013.jpg&prop=imageinfo&iiprop=comment|url|dimensions&format=xml&iiurlwidth=300"; //show 1st image
private const string url1_Image2 = "https://en.wikipedia.org/w/api.php?action=query&titles=File:Neuschwanstein%20castle.jpg&prop=imageinfo&iiprop=comment|url|dimensions&format=xml&iiurlwidth=300";// show another image
private const string url1_Image3 = "https://en.wikipedia.org/w/api.php?action=query&titles=File:Hohenschwangau_-_Schloss_Neuschwanstein5.jpg&prop=imageinfo&iiprop=comment|url|dimensions&format=xml&iiurlwidth=300";// show another image
public WikiForm()
{
InitializeComponent();
}
XDocument xmlDocument1 = XDocument.Load(url1_Image1);
XDocument xmlDocument2 = XDocument.Load(url1_Image2);
XDocument xmlDocument3 = XDocument.Load(url1_Image3);
var image1 = (from page in xmlDocument1.Descendants("page")
select new AllImage
{
Title1 = page.Attribute("title").Value,
Imagerepository1 = page.Attribute("imagerepository").Value,
Url1 = page.Element("imageinfo").Element("ii").Attribute("thumburl").Value
});
ShowImages1(image1);
var image2 = (from page in xmlDocument2.Descendants("page")
select new AllImage
{
Title2 = page.Attribute("title").Value,
Imagerepository2 = page.Attribute("imagerepository").Value,
Url2 = page.Element("imageinfo").Element("ii").Attribute("thumburl").Value
});
ShowImages2(image2);
var image3 = (from page in xmlDocument3.Descendants("page")
select new AllImage
{
Title3 = page.Attribute("title").Value,
Imagerepository2 = page.Attribute("imagerepository").Value,
Url3 = page.Element("imageinfo").Element("ii").Attribute("thumburl").Value
});
ShowImages3(image3);
}
private void ShowImages1(IEnumerable<AllImage> image1)
{
var image = image1.First();
pictureLabel1.Text = image.Title1;
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.LoadAsync(image.Url1);// asynchronous loading
}
private void ShowImages2(IEnumerable<AllImage> image2)
{
var image = image2.First();
pictureLabel2.Text = image.Title2;
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox2.LoadAsync(image.Url2);// asynchronous loading
}
private void ShowImages3(IEnumerable<AllImage> image3)
{
var image = image3.First();
pictureLabel3.Text = image.Title3;
pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox3.LoadAsync(image.Url3);// asynchronous loading
}
}
You need something like
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false; // to prevent a new download until you have finished the old one
XDocument xmlDocument = XDocument.Load(url1_Image);
var images = (from page in xmlDocument.Descendants("page")
select new AllImage
{
Title = page.Attribute("title").Value,
Imagerepository = page.Attribute("imagerepository").Value,
Url = page.Element("imageinfo").Element("ii").Attribute("url").Value
});
ShowImages(images);
};
private void ShowImages(IEnumerable<AllImage> images)
{
var image = images.First();
label1.Text = image.Title;
pictureBox1.LoadAsync(image.Url); // asynchronous loading
}
After downloading the image you need to make the button available.
void pictureBox1_LoadCompleted(object sender, AsyncCompletedEventArgs e)
{
button1.Enabled = true;
}
We strongly recommend to give normal names to the controls. For example, buttonLoad, labelTitle, pictureBoxWikiImage.
In addition, I see in XML information about only one image. So, for what the IEnumerable collection?
i just used this snippet for creating a tray application with two buttons (settings and exit):
using System;
using System.Windows.Forms;
using System.Drawing;
using WindowsFormsApplication1;
//*****************************************************************************
abstract class NotIco
{
private static NotifyIcon notico;
//==========================================================================
public static void Main(string[] astrArg)
{
ContextMenu cm;
MenuItem miCurr;
cm = new ContextMenu();
miCurr = new MenuItem();
miCurr.Index = 0;
miCurr.Text = "&Settings";
miCurr.Click += new System.EventHandler(SettingsClick);
cm.MenuItems.Add(miCurr);
miCurr = new MenuItem();
miCurr.Index = 1;
miCurr.Text = "Beenden";
miCurr.Click += new System.EventHandler(ExitClick);
cm.MenuItems.Add(miCurr);
notico = new NotifyIcon();
notico.Icon = new Icon("tanss.ico");
notico.Text = "TANSS Busylight Connector";
notico.Visible = true;
notico.ContextMenu = cm;
notico.DoubleClick += new EventHandler(NotifyIconDoubleClick);
Application.Run();
}
//==========================================================================
protected static void ExitClick(Object sender, EventArgs e)
{
notico.Dispose();
Application.Exit();
}
//==========================================================================
protected static void SettingsClick(Object sender, EventArgs e)
{
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
// This should open the "Settings"-Popup, containing 3 textboxes and a button to save them to xml.
}
//==========================================================================
protected static void NotifyIconDoubleClick(Object sender, EventArgs e)
{
// ...
}
}
Now i want to open a new Form as a Popup containing 3 textboxes to write some values in and a button to save them.
In the background, a never ending loop is requesting a url and parsing a value out of a json.
could you help me opening the new form (its not made yet, i just need it to open first :/)
and where do i embedd my background loop-code?
thanks so much!
It is as simple as
MyForm form1 = new MyForm();
form1.Show();
You have to create a new form object and show it on screen.
and, if you want to, you can set all others properties
form1.Location = new Point(20, 20);
form1.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
form1.MaximizeBox = true;
form1.ControlBox = true;
......
I think is better (easier actually) to create the form from the designer and avoid the creation of every textbox and everything from code.