Draw Polygon in Googlemap based marker time - c#

I want to draw a polygon by connecting markers in googlemap.Time is associated with each marker.So i want connect each points based on the time.How can i do this.Currently code is impleneted like this.Where i need to change.
var marker = new Array();
var points = new Array();
for(var i=0;i<value.length;i++)
{
var tempar=value[i].split(',');
var center = new GLatLng(tempar[0], tempar[1]);
var mar = new GMarker(center, icon);
var imgpth=tempar[3];
var tme=tempar[2];
marker.push(mar);
marker[i].time = tempar[2];
points.push(marker[i].getLatLng());
drawMarker(mar,imgpth,tme);
}
for(i=;i<marker.length;i++)
{
map.addOverlay(marker[i]);
}
var polyline = new GPolygon(points, "#f33f00", 2, 1, "#ff0000", 0.2);
map.addOverlay(polyline);

The easiest way to do this is to sort marker array by time. Assuming that the time property has some sensible values (not strings):
marker.sort(function(a,b){return a.time-b.time});
If the time is a string then:
marker.sort(function(a,b) {
var date1 = new Date(a.time);
var date2 = new Date(b.time);
return date1.getTime() - date2.getTime();
});

Related

c#, autocad plugins, Updating text of object properties

I need to write AutoCAD plugin to display the area of the object.
Below is my code.
It works fine, but test is static. I need to keep tracking the area of the circle cir.Area.ToString();.
Currently, If I change the size of the circle latter on, the text does not change anymore.
For example, the area of my circle is 10. I run code, it displays 10. But if I change the radius of circle, the text remains 10.
How can I make it working.
[CommandMethod("displayarea")]
public static void Displayarea()
{
var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var filter = new SelectionFilter(new[] { new TypedValue(0, "Circle") });
var selection = ed.GetSelection(filter);
if (selection.Status != PromptStatus.OK)
return;
using (var tr = db.TransactionManager.StartTransaction())
{
var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
foreach (var id in selection.Value.GetObjectIds())
{
var ids = new ObjectIdCollection(new[] { id });
Circle cir = (Circle)tr.GetObject(id, OpenMode.ForRead) as Circle;
var _centerPosition = cir.Center;
using (DBText acText = new DBText())
{
acText.Position = _centerPosition;
acText.TextString = cir.Area.ToString();
acText.Height = 0.5;
curSpace.AppendEntity(acText);
tr.AddNewlyCreatedDBObject(acText, true);
}
}
tr.Commit();
}
}
Also you can use oEntity.Modified += OEntity_Modified;
Find this: Find which properties changed on modified event
You need to use fields.
Find this:
https://www.keanw.com/2007/07/accessing-the-a.html
It works by replacing
cir.Area.ToString();
to
string circarea = "%<\\AcObjProp Object(%<\\_ObjId "
+ CircleId
+ ">%).Area \\f \"%lu2\">%";

How to remove a single DataLabel from a Chart made with EPPlus and C#

Is it possible in any way to remove a single DataLabel from a Chart made with EPPlus and C#?
I just want to remove a single one, not the setting for the hole Chart...
How can the collection of DataLabels be accessed (dLbls > dLbl)?
var chart = (ExcelBarChart)worksheet.Drawings.AddChart("Chart", eChartType.ColumnStacked);
Also made use of coloring a individual point of Chart with this:
Legend color is incorrect in excel chart created using EPPlus
(The red point at the upper right)
Now I want to remove a specific label of a point, with generally applied DataLabels...
chart.DataLabel.ShowValue = true;
Any hint appreciated.
I figured out a solution. This Extension method is doing the trick...
public static void RemoveDataLabel(this ExcelBarChart chart, int serieNumber, int objectNumber)
{
var chartXml = chart.ChartXml;
var nsa = chart.WorkSheet.Drawings.NameSpaceManager.LookupNamespace("a");
var nsuri = chartXml.DocumentElement.NamespaceURI;
var nsm = new XmlNamespaceManager(chartXml.NameTable);
nsm.AddNamespace("a", nsa);
nsm.AddNamespace("c", nsuri);
var dLbls = chart.ChartXml.SelectSingleNode(#"c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[c:idx[#val='" + serieNumber + "']]/c:dLbls", nsm);
var dLbl = chartXml.CreateNode(XmlNodeType.Element, "dLbl", nsuri);
var idx = chartXml.CreateNode(XmlNodeType.Element, "idx", nsuri);
var valueIdx = chartXml.CreateAttribute("val", nsuri);
valueIdx.Value = objectNumber.ToString();
idx.Attributes.Append(valueIdx);
dLbl.AppendChild(idx);
var delete = chartXml.CreateNode(XmlNodeType.Element, "delete", nsuri);
var valueDelete = chartXml.CreateAttribute("val", nsuri);
valueDelete.Value = "1";
delete.Attributes.Append(valueDelete);
dLbl.AppendChild(delete);
dLbls.AppendChild(dLbl);
}

iTextSharp - How can I iterate tables side by side in C# winforms?

I have a book library and I want to print library labels for them. When you select books from GridControl and click Print Labels button, the program creates labels on a pdf file like this:
private void btnQRPrintLabels_Click(object sender, EventArgs e)
{
// These are books' ids. Normally, these are retrieved from GridControl element.
var books_ids = new List<int>() {1, 2, 5, 6, 7, 12};
// I don't use PanelControl. But in the future, maybe I can use it later.
CreateLabels(books_ids, panelControl1);
}
And here is the contents of CreateLabels method:
public void CreateLabels(List<int> books_ids, PanelControl p)
{
var doc = new Document(PageSize.A4, 10, 10, 10, 10);
var m = new SaveFileDialog
{
Filter = #"PDF File Format|*.pdf",
FileName = "Labels.pdf"
};
if (m.ShowDialog() != DialogResult.OK) return;
var file = new FileStream(m.FileName, FileMode.Create);
wr = PdfWriter.GetInstance(doc, file);
doc.Open();
cb = wr.DirectContent;
wr.PageEvent = this;
// Labels are created from this method.
Labels(doc, books_ids);
doc.Close();
}
Finally, the contents of Labels method:
protected void Labels(Document doc, List<int> books_ids)
{
var i = 1;
foreach (var book_id in books_ids)
{
var alignment = (i % 2 != 0) ? Element.ALIGN_LEFT : Element.ALIGN_RIGHT;
// Book's informations are retrieved from Linq Connect Model.
var _connection = new LinqtoSQLiteDataContext();
var book = _connection.books.SingleOrDefault(b_no => b_no.id == book_id);
// Outer table to get rounded corner...
var table = new PdfPTable(1) { WidthPercentage = 48, HorizontalAlignment = alignment };
// Inner table: First cell for QR code and second cell for book's informations.
var inner_table = new PdfPTable(2) { WidthPercentage = 100 };
inner_table.DefaultCell.Border = Rectangle.NO_BORDER;
var inner_measurements = new[] { 40f, 60f };
inner_table.SetWidths(inner_measurements);
// Generate QR code in the `Tools` class, `GenerateQR` method.
System.Drawing.Image image = Tools.GenerateQR(100, 100, book?.isbn);
var pdfImage = iTextSharp.text.Image.GetInstance(image, System.Drawing.Imaging.ImageFormat.Jpeg);
var qr = iTextSharp.text.Image.GetInstance(pdfImage);
var a = new PdfPCell(qr) { Border = Rectangle.NO_BORDER };
var b = new PdfPCell(new Phrase(book?.name, font_normal)) { Border = Rectangle.NO_BORDER };
inner_table.AddCell(a);
inner_table.AddCell(b);
var s = new PdfPCell(inner_table)
{
CellEvent = new RoundRectangle(),
Border = Rectangle.NO_BORDER,
Padding = 2,
HorizontalAlignment = Element.ALIGN_LEFT
};
table.AddCell(s);
doc.Add(table);
i++;
}
}
These codes bring me labels like this:
But I want to get labels like this:
Because if I manage getting labels side by side, I print it to computer labels easily. Here is the computer label that I want to print to on it:
How can I iterate tables side by side?
Use one outer Table with
new PdfPTable(2) { WidthPercentage = 100 }
Then add all your inner tables to this one and at last add the outer table to the document. This way there is NO need to use that toggeling left/right alignment.
:edit:
var table = new PdfPTable(2) { WidthPercentage = 100 };
foreach (var book_id in books_ids)
{
// Book's informations are retrieved from Linq Connect Model.
var _connection = new LinqtoSQLiteDataContext();
var book = _connection.books.SingleOrDefault(b_no => b_no.id == book_id);
// Outer table to get rounded corner...
// Inner table: First cell for QR code and second cell for book's informations.
var inner_table = new PdfPTable(2) { WidthPercentage = 100 };
inner_table.DefaultCell.Border = Rectangle.NO_BORDER;
var inner_measurements = new[] { 40f, 60f };
inner_table.SetWidths(inner_measurements);
// Generate QR code in the `Tools` class, `GenerateQR` method.
System.Drawing.Image image = Tools.GenerateQR(100, 100, book?.isbn);
var pdfImage = iTextSharp.text.Image.GetInstance(image, System.Drawing.Imaging.ImageFormat.Jpeg);
var qr = iTextSharp.text.Image.GetInstance(pdfImage);
var a = new PdfPCell(qr) { Border = Rectangle.NO_BORDER };
var b = new PdfPCell(new Phrase(book?.name, font_normal)) { Border = Rectangle.NO_BORDER };
inner_table.AddCell(a);
inner_table.AddCell(b);
PdfPCell labelCell = new PdfPCell(inner_table)
{
CellEvent = new RoundRectangle(),
Border = Rectangle.NO_BORDER,
Padding = 2,
HorizontalAlignment = Element.ALIGN_LEFT
};
table.AddCell(labelCell);
}
doc.Add(table);
Just add page-level table (2 columns, 6 rows) and place each label into individual cell in this page-level table.

Intersection between two geographic lines

I'm using the DotSpatial C# library and I'm trying to use the following code to try to find the intersection point between two lines (I know they do intersect)
var geoproj = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984;
var d1 = new FeatureSet { Projection = geoproj };
//var c1 = new Coordinate(31.877484, 34.736723);
//var c2 = new Coordinate(31.879607, 34.732362);
var c1 = new Coordinate(0, -1);
var c2 = new Coordinate(0, 1);
var line1 = new LineString(new[] { c1, c2 });
d1.AddFeature(line1);
var d2 = new FeatureSet { Projection = geoproj };
//var c3 = new Coordinate(31.882391, 34.73352);
//var c4 = new Coordinate(31.875502, 34.734851);
var c3 = new Coordinate(-1, 0);
var c4 = new Coordinate(1, 0);
var line2 = new LineString(new[] { c3, c4 });
d2.AddFeature(line2);
var inters = d1.Intersection(d2, FieldJoinType.All, null);
var feats = inters.Features;
foreach (var feat in feats)
{
Console.WriteLine("{0}", feat.ToString());
}
The resulting feature set is always empty.
What am I doing wrong?
I also tried to swap the X and Y components for each coordinate (in case the first was assumed to be the longitude instead of the latitude)
Thanks!
EDIT: As per weston's comment below, I've changed the coordinates of the two lines to more obviously intersecting ones. The result is the same.
The intersection code you are using is basically a very limited shortcut. It is stuck with two conflicting ideas. The first idea is that featuresets all have the same feature type. That is, if you are working with a polygon featureset, all the features are polygons. The second idea is that the "intersection" of two lines is rarely a line. It is usually a point. So really that featureset intersecting code is designed to be used for intersecting polygons where the resulting shape is usually a polygon. It will also work for points where the results are always points. In your case, you probably want to find the union of the intersecting shapes, and throw out the shapes that do not intersect. You can accomplish this most easily by taking control of the features in a loop like the ones below. I have three examples, one that creates a point featureset from the intersections, and just assumes that all intersections will be points, one that keeps the original d1 feature if it intersects with a d2 feature, and another that unions all the intersecting d2 features with each d1 feature. This has the potential of creating some duplication of d2 content if a d2 feature intersects with more than one d1 feature. In any of these cases, it may not be clear what to do with the attributes, since the intersection could officially possess attributes that belong to multiple d2 shapes, not just one, so that would also have to be handled in a custom way that is meaningful for your specific application.
var geoproj = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984;
var d1 = new FeatureSet { Projection = geoproj };
//var c1 = new Coordinate(31.877484, 34.736723);
//var c2 = new Coordinate(31.879607, 34.732362);
var c1 = new Coordinate(0, -1);
var c2 = new Coordinate(0, 1);
var line1 = new LineString(new[] { c1, c2 });
d1.AddFeature(line1);
var d2 = new FeatureSet { Projection = geoproj };
//var c3 = new Coordinate(31.882391, 34.73352);
//var c4 = new Coordinate(31.875502, 34.734851);
var c3 = new Coordinate(-1, 0);
var c4 = new Coordinate(1, 0);
var line2 = new LineString(new[] { c3, c4 });
d2.AddFeature(line2);
// To create a Point featureset with the intersections
var result = new FeatureSet(FeatureType.Point) { Projection = geoproj };
foreach (IFeature feature in d1.Features)
{
foreach (IFeature other in d2.Features)
{
if (feature.Intersects(other))
{
result.AddFeature(feature.Intersection(other));
}
}
}
// To keep only d1 lines that intersect with d2
result = new FeatureSet { Projection = geoproj };
foreach(IFeature feature in d1.Features){
foreach(IFeature other in d2.Features){
if(feature.Intersects(other)){
result.AddFeature(feature);
}
}
}
// Alternately to combine the intersecting lines into a cross
result = new FeatureSet { Projection = geoproj };
foreach (IFeature feature in d1.Features)
{
IFeature union = feature;
Boolean keep = false;
foreach (IFeature other in d2.Features)
{
if (feature.Intersects(other))
{
union = union.Union(other);
keep = true;
}
}
if (keep)
{
result.AddFeature(union);
}
}

Converting data from discrete properties of objects in an IEnumerable into an array/series for charting?

I have an IEnumerable (List<>) of a particular Type. The Type has a set of properties which I would like to chart as individual series (MVC3/Razor).
Is there a way I can transpose the data in the list of objects into a list of the properties?
e.g.
Given the code below, the end result I am trying to acheive is a set of Series so I have
Bucket1: IEnumerable<Date, Value>
Bucket2: IEnumerable<Date, Value>
etc
So that I can then chart each series to get a line chart with Date on x and value on y, for (in this example) 3 series/lines. This code works perfectly, but just feels wrong somehow?
var buckets = new List<Bucket>(){
new Bucket{
Date=DateTime.Today.AddDays(-3),
Bucket1=1000,
Bucket2=2000,
Bucket3=3000},
new Bucket{
Date=DateTime.Today.AddDays(-2),
Bucket1=1000,
Bucket2=2020,
Bucket3=3300},
new Bucket{
Date=DateTime.Today.AddDays(-1),
Bucket1=1000,
Bucket2=2040,
Bucket3=3600}
};
var chart = new Chart(){ Height = 400, Width = 600 };
var area = new ChartArea();
chart.ChartAreas.Add(area);
var series1 = chart.Series.Add("Bucket 1");
var series2 = chart.Series.Add("Bucket 2");
var series3 = chart.Series.Add("Bucket 3");
foreach (var series in chart.Series)
{
series.ChartType = SeriesChartType.Line;
}
foreach (var item in buckets)
{
series1.Points.AddXY(item.Date, item.Bucket1);
series2.Points.AddXY(item.Date, item.Bucket2);
series3.Points.AddXY(item.Date, item.Bucket3);
}
What about just using a Lambda expression for each serie (code below was not tested - it's just a prototype):
var series1 = buckets.Select(b => new { b.Date, b.Bucket1 });
var series2 = buckets.Select(b => new { b.Date, b.Bucket2 });
Thanks to the comments posted I kept my original code and don't think there's an easier way to do this.

Categories