Little Help - C#
Sean Gillies
sgillies at FRII.COM
Wed Dec 14 21:44:35 PST 2005
On Dec 14, 2005, at 8:13 PM, Ian Erickson wrote:
> Alright,
>
> I've compiled a working version of the mapscript_csharp assembly and
> everything seems to be working fine. I can load, enumerate the
> layers,
> and save a copy of the image to the file system. However, I need
> to add
> a point to a dynamically created layer (all of this mind you in C#).
> Here's what I've got:
>
> mapObj m_obj = new mapObj(@"C:\base.map");
>
> layerObj layer = new layerObj(m_obj);
> layer.name = "PointLayer";
> layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
> layer.setProjection("init=epsg:4326");
> layer.status = 1;
>
> classObj c = new classObj(layer);
> c.label.type = MS_FONT_TYPE.MS_TRUETYPE;
> c.label.font = "arial";
> c.label.size = 7;
> c.label.color.setRGB(0, 0, 0);
> c.label.outlinecolor.setRGB(255, 255, 255);
>
> styleObj style = new styleObj(c);
> style.symbolname = "circle";
> style.size = 14;
> style.color.setRGB(0, 255, 0);
> style.outlinecolor.setRGB(0, 0, 0);
>
> Console.WriteLine ("# Map layers " + m_obj.numlayers + "; Map
> name = " + m_obj.name);
> for (int i=0; i<m_obj.numlayers; i++)
> {
> Console.WriteLine("Layer [" + i + "] name: " +
> m_obj.getLayer(i).name);
> }
>
> imageObj i_obj = m_obj.draw();
>
> pointObj p = new pointObj(-111.4752, 33.377321, 0.0, 0.0);
>
> lineObj l = new lineObj();
> l.add(p);
>
> shapeObj s = new shapeObj(0);
> s.add(l);
> s.text = "TEXT";
>
> layer.addFeature(s);
>
> p.draw(m_obj, layer, i_obj, 0, "TEXT");
Ian,
The last two lines here are redundant. There are 3 different ways to
render a point.
1) pointObj#draw
2) shapeObj#draw
3) layer#addFeature and then layer#draw
You're doing a little bit of each. I recommend that you go with #1
and delete the lines in between the creation of the new point, and
p.draw().
>
> s.Dispose();
> l.Dispose();
> p.Dispose();
>
> Console.ReadLine();
>
> As I mentioned, the assembly is creating the appropriate file, and
> everything seems to be working - with the exception of creating a
> point
> symbol on the new layer. No exceptions are thrown so I must be
> missing
> something crucial. If anyone can provide some hints, I'd be grateful!
>
How do you know that points are not drawn? Are you saving the
imageObj? I can't tell from the code.
---
Sean Gillies
sgillies at frii dot com
http://zcologia.com/news
More information about the MapServer-users
mailing list