Building with 2.x

Topics: SharpMap v2.0
Jan 30, 2008 at 12:00 AM
Has anyone successfully built a winforms test project with the latest NTS, GeoAPI, and SharpMap?

I've modified SharpMap.Presentation.WinForms and DemoWinForm such that they compile, but I cannot get an NTS Geometry factory successfully created. I'm using the statement:

_geometryFactory = new GeometryFactory<BufferedCoordinate2D>(new BufferedCoordinate2DSequenceFactory(new BufferedCoordinate2DFactory(), null));

I'm sure the Null is not correct, for the second paramter on the BufferedCoordinateSequenceFactory, but I have no clue what object I would supply there that implements the requested NPack interface.

Actually, though, the error I'm getting is because the NTS GeometryFactory creates a bunch of predefined geometry factories before the constructor is called. And as such, the DefaultCoordinateFactory is undefined. Every time I get a build of NTS down, I comment out all of those default factory declarations, but surely I must be using the wrong factory.

CodeKaizen.. two weeks go we discussed having an independent assembly that implemented the Coordinate objects. That would be great.
Coordinator
Jan 30, 2008 at 1:12 PM
Like you I have got close.. but no cigar yet.. Have you seen the SharpMap.SimpleGeometries project? there is a new GeometryFactory there.. but last time i checked it was not implemented. Also the latest drop of the NPack source I downloaded had some files missing - I think there are some changes going on there that bubble up to GeoAPI/NTS etc.. For the time being I'm concentrating on other things.. I'll get back to it as soon as I can build NPack again..
Jan 30, 2008 at 11:30 PM
Yes, I have explored the geometry factory in both NTS and SharpMap.SimpleGeometries. Neither are implemented.

I don't know if we are supposed to step up an implement them, or if there is a geometry factory floating around somewhere that is being used in testing but not checked in or what. We have resources available to help on this effort. I just wish I had some direction on how to use them efficiently. We're about to get into a critical situation, though. I'm committed to release a very simple viewer application with this technology by the end of February. I'm getting quite worried.

As to NPack... I'm just using the dll in external references. I really don't want to have to start building that, too. I'm already concerned about the effort it takes to implement the NPack interfaces when you want to create what would otherwise be a simple geometry object.
Coordinator
Jan 31, 2008 at 9:10 AM
I know what you mean. I am quite prepared to step up but I need to know where to deliver stuff to/ what to deliver in the first place..

RE NPack, the reason i mentioned it was that some of the existing interfaces were starting to implement other interfaces which I think had an impact on IVector/IMatrix and on to ICoordinate. WRT the effort required to implement them personally I think it only really has to be done once for 2D and once for 3D but does simplify rendering accross GDI/DX/WPF etc so I think it is a good move.. Utlimately all the complexities can be hidden away behind an abstraction.

Could you do your viewer with beta1... a long time ago I did have a rendering implementation using it - buggy but it proved a point..
Jan 31, 2008 at 11:02 AM


JohnDiss wrote:

Could you do your viewer with beta1... a long time ago I did have a rendering implementation using it - buggy but it proved a point..


All of our stuff is heavily dependent upon NTS. We are using the October build of NTS and GeoAPI in our production work. I guess I could try to use the NTS provider and see how it goes. We have some special rendering needs, though, and I didn't want to write that code in Beta 1 when the new SharpMap is going to be so much better. I have two other options... try to convince my client to let us release the view using COM. Then I could use my existing GIS engine. Or look at purchasing ThinkGeo. They have a native .Net solution, but I can't implemented the required rendering.

I might bug you for a working copy of Beta 1 in a couple of weeks :)
Coordinator
Jan 31, 2008 at 11:32 AM


I might bug you for a working copy of Beta 1 in a couple of weeks :)


all it was was a hacked version of the Demo win form with a few fixes to read a shape file and draw the geoms.. just a tester to see where the sm project was up to at the time.. I probably still have a copy at home - but dont expect too much..

I agree it seems a shame to go back to a previous point knowing that the newer stuff is much better.. I get the feeling that everything will fall into place soon though. Looking through the code a lot of it should drop into place when the Coordinates and factories are done - there may be bugs but we can all help with that..
Jan 31, 2008 at 12:49 PM

John, at your convenience, if you have a running solution for Beta 1, and could just zip and e-mail the full folder structure, I could look at whether we can fit our data provider into it. Just if it is convenient. My e-mail address is in my profile.
Coordinator
Jan 31, 2008 at 1:20 PM
Edited Jan 31, 2008 at 10:21 PM
@magnum sorry i just sent you this file in parts: much easier left here. It was built against the beta1 binaries not the source - so it is subject to any exceptions bubbling up..
If it does not build against the binaries you download drop me a mail - you should have my email and I'll send you mine..
There are two parts here designer and form.. It doesn't do much at all but it does draw a shapefile on the screen.. HTH jd
/* designer */
namespace TestSmv2b1
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.mapViewControl1 = new SharpMap.Presentation.WinForms.MapViewControl();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.addLayerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// mapViewControl1
//
this.mapViewControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.mapViewControl1.Location = new System.Drawing.Point(0, 24);
this.mapViewControl1.Name = "mapViewControl1";
this.mapViewControl1.Size = new System.Drawing.Size(1054, 739);
this.mapViewControl1.TabIndex = 0;
this.mapViewControl1.Text = "mapViewControl1";
this.mapViewControl1.Title = "mapViewControl1";
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.addLayerToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(1054, 24);
this.menuStrip1.TabIndex = 1;
this.menuStrip1.Text = "menuStrip1";
this.menuStrip1.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.menuStrip1_ItemClicked);
//
// addLayerToolStripMenuItem
//
this.addLayerToolStripMenuItem.Name = "addLayerToolStripMenuItem";
this.addLayerToolStripMenuItem.Size = new System.Drawing.Size(72, 20);
this.addLayerToolStripMenuItem.Text = "Add Layer";
this.addLayerToolStripMenuItem.Click += new System.EventHandler(this.addLayerToolStripMenuItem_Click);
//
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1054, 763);
this.Controls.Add(this.mapViewControl1);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "Form1";
this.Text = "Form1";
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private SharpMap.Presentation.WinForms.MapViewControl mapViewControl1;
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem addLayerToolStripMenuItem;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
}
}
/* Form*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SharpMap;
using SharpMap.Layers;
using SharpMap.Data.Providers.ShapeFile;
using SharpMap.Styles;

namespace TestSmv2b1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
mapViewControl1.Map = map;
}
Map map = new Map("My Map");

Random rnd = new Random();


private VectorStyle RandomStyle()
{

VectorStyle vs = new VectorStyle();
vs.Enabled = true;
vs.EnableOutline = true;
vs.Fill = new SolidStyleBrush(RandomColor());
vs.Line = new StylePen(RandomColor(), 3);
vs.MaxVisible = double.MaxValue;
vs.MinVisible = double.MinValue;
vs.RenderingMode = StyleRenderingMode.HighQuality;
return vs;
}


private StyleColor RandomColor()
{
return StyleColor.FromBgra(rnd.Next(255), rnd.Next(255), rnd.Next(255), rnd.Next(80, 255));

}

private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{

}

private void addLayerToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK )
{
AddLayer(openFileDialog1.FileName);
ZoomToExtents();
}
}

private void ZoomToExtents()
{
mapViewControl1.Map = map;
mapViewControl1.ZoomToExtents();
}

void AddLayer(string path)
{
FeatureLayer fl = new GeometryLayer(Guid.NewGuid().ToString(), RandomStyle(), new ShapeFileProvider(path));
fl.DataSource.Open();
map.Layers.Add(fl);




}
}
}
Jan 31, 2008 at 11:58 PM
Thank you!

And, I've learned that Codekaizen just had a baby! Well... he was part of it anyway.
Coordinator
Feb 1, 2008 at 8:54 AM
I thought there must be a reason he had been so quiet!

@Codekaisen Congratulations!!..


did the file build ok with the beta1 binaries? jd


Magnum4610 wrote:
Thank you!

And, I've learned that Codekaizen just had a baby! Well... he was part of it anyway.

Feb 1, 2008 at 10:52 AM


JohnDiss wrote:

did the file build ok with the beta1 binaries? jd



I don't think I will be able to look at it until early next week. I'll let you know.