How do i draw a polyline in android studio for array of coordinates? - polyline

http://107.180.68.111:84/ZIGAPICleveland/api/Trip/GetAllShapes?Page=0
this is the api i got and how do i draw a polyline for this?

here is the code, first get an ArrayList of coordinates from the above link using JSON parser then use this code
PolylineOptions polylineOptions = new PolylineOptions().
geodesic(true).
color(Color.BLUE).
width(10);
for (int i = 0; i < coordinates.size(); i++)
polylineOptions.add(coordinates.get(i));
mMap.addPolyline(polylineOptions);
here coordinates is the arraylist of location coordinates, mMap is GoogleMap object

Related

How to create circle or buffer of 1 KM around specified waypoint in arcGIS JAVA SDK?

I'm using this code snippet to draw circle, Circle shape is fine but circle covers even thousand km during zoom-out. I need to fix this circle around specified radius.
private void addPointGraphic(double lat, double lng, float radius) {
if (graphicsOverlay != null) {
Viewpoint viewpoint = new Viewpoint(latitude, longitude, 12);
final ListenableFuture<Boolean> viewpointSetFuture = mapView.setViewpointAsync(viewpoint, 5);
SimpleMarkerSymbol pointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, color, radius);
pointSymbol.setOutline(new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, hexGreen, 1.5f));
Point point = new Point(lng, lat, SpatialReferences.getWgs84());
Graphic pointGraphic = new Graphic(point, pointSymbol);
graphicsOverlay.getGraphics().add(pointGraphic);
}
}
The ArcGIS Runtime SDK for Java has many samples available for different workflows.
Perhaps the Buffer sample suits what you are trying to do:
https://github.com/Esri/arcgis-runtime-samples-java/tree/master/geometry/buffer
Esri's GeoNet forums also have dedicated message boards for all the SDKs, so any perticular questions regarding the Java SDK might get more visibility from that community there:
https://community.esri.com/t5/arcgis-runtime-sdk-for-java/bd-p/arcgis-runtime-sdk-for-java-questions

How to use a QSGSimpleTextureNode?

I'm trying to understand how do I use a QSGSimpleTextureNode but Qt documentation is very vague. I want to render text on the scene graph, so basically what I want is to draw a texture with all the glyphs and then set that texture on a QSGSimpleTextureNode. My idea was to create the texture using standard OpenGL code and set the texture data to the data I have just created. I can't find an example to show me how to achieve this.
I would use QSGGeometryNode instead of QSGSimpleTextureNode. If I am not wrong it is not possible to set the texture coordinates in a QSGSimpleTextureNode. You could write a custom QQuickItem for the SpriteText and override the updatePaintNode:
QSGNode* SpriteText::updatePaintNode(QSGNode *old, UpdatePaintNodeData *data)
{
QSGGeometryNode* node = static_cast<QSGGeometryNode*>(old);
if (!node){
node = new QSGGeometryNode();
}
QSGGeometry *geometry = NULL;
if (!old){
geometry = new QSGGeometry(QSGGeometry::defaultAttributes_TexturedPoint2D()
,vertexCount);
node->setFlag(QSGNode::OwnsGeometry);
node->setMaterial(material); // <-- Texture with your glyphs
node->setFlag(QSGNode::OwnsMaterial);
geometry->setDrawingMode(GL_TRIANGLES);
node->setGeometry(geometry);
} else {
geometry = node->geometry();
geometry->allocate(vertexCount);
}
if (textChanged){
//For every Glyph in Text:
//Calc x + y position for glyph in texture (between 0-1)
//Create vertexes with calculated texture coordinates and calculated x coordinate
geometry->vertexDataAsTexturedPoint2D()[index].set(...);
...
node->markDirty(QSGNode::DirtyGeometry);
}
//you could start timer here which call update() methode
return node;
}

Draw polygon and detect if a marker is inside

I have these coordinates stored in a field of a database for drawing a polygon on a google map. I want to detect if a marker is inside this polygon:
(37.15730677081955, -3.7892532348632812),
(37.13486648362684, -3.7593841552734375),
(37.16059015678727, -3.7027359008789062)
Does anyone know how to get it?
You can use google map geometry library containsLocation() method with something like this:
for (var j=0; j < allMarkers.length; j++){
for (var i=0; i < createdShapes.length; i++) {
var latlong = allMarkers[j].getPosition();;
if(google.maps.geometry.poly.containsLocation(latlong, createdShapes[i]) == true) {
allMarkers[j].setOptions({
icon : "http://labs.google.com/ridefinder/images/mm_20_white.png",
});
}
}
Here is some code written in Java to detect if a GPS Coordinate is inside a lat/long bounding box, it is mathematical, so it could probably be translated to other languages.
Detecting whether a GPS coordinate falls within a polygon on a map

Is it possible to draw image using QGraphicsView from a 2D BYTE array Qt?

I have a 2D BYTE (unsigned char) array. buf[50][100] which is having some data. I need to draw this buffer to an image in Qt using QGraphicsView. The byte in (x,y) represents the (x,y)th pixel of the array. How to pass this array to the QGraphicsView to draw very fast? Or is there any other method (without using QGraphicsView) to draw the image in 2D array Please help.
You can create a QImage object from a pre-existing memory area and then you can use a drawImage call to draw it on a normal QPainter.
Being your image 8 bit per pixel you will need to also set up a palette for the image.
The palette is simply a mapping from a byte index to a QRgb color value. You can set it up like so:
static void setGrayColorMap(QImage * img)
{
img->setColorCount(256);
for (int i = 0; i < 256; ++i) {
img->setColor(i, qRgb(i,i,i));
}
}

Plot points instead of lines? JFreeChart PolarChart

Currently, the PolarChart joins all the coordinates with lines creating a polygon. I just want it to plot each point with a dot and NOT join them together. Is this possible?
I have tried using translateValueThetaRadiusToJava2D() and Graphics2D to draw circles but it's very clunky and contrived.
Any suggestions welcome!
So the DefaultPolarItemRenderer takes in all the polar points, converts the polar points to regular Java2D coordinates, makes a Polygon with those points and then draws it. Here's how I got it to draw dots instead of a polygon:
public class MyDefaultPolarItemRenderer extends DefaultPolarItemRenderer {
#Override
public void drawSeries(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea, PlotRenderingInfo info, PolarPlot plot, XYDataset dataset, int seriesIndex) {
int numPoints = dataset.getItemCount(seriesIndex);
for (int i = 0; i < numPoints; i++) {
double theta = dataset.getXValue(seriesIndex, i);
double radius = dataset.getYValue(seriesIndex, i);
Point p = plot.translateValueThetaRadiusToJava2D(theta, radius,
dataArea);
Ellipse2D el = new Ellipse2D.Double(p.x, p.y, 5, 5);
g2.fill(el);
g2.draw(el);
}
}
}
and then instantiated this class elsewhere:
MyDefaultPolarItemRenderer dpir = new MyDefaultPolarItemRenderer();
dpir.setPlot(plot);
plot.setRenderer(dpir);
This one's a little harder. Given a PolarPlot, you can obtain its AbstractRenderer and set the shape. For example,
PolarPlot plot = (PolarPlot) chart.getPlot();
AbstractRenderer ar = (AbstractRenderer) plot.getRenderer();
ar.setSeriesShape(0, ShapeUtilities.createDiamond(5), true);
The diamond will appear in the legend, but the DefaultPolarItemRenderer neither renders shapes, nor provides line control. You'd have to extend the default renderer and override drawSeries(). XYLineAndShapeRenderer is good example for study; you can see how it's used in TimeSeriesChartDemo1.
If this is terra incognita to you, I'd recommend The JFreeChart Developer Guide†.
†Disclaimer: Not affiliated with Object Refinery Limited; I'm a satisfied customer and very minor contributor.
This is an excellent discussion, in case you want the function to pick up the color assigned by user to the series
add ...
Color c =(Color)this.lookupSeriesPaint(seriesIndex);
g2.setColor(c);
before ...
g.draw(e1);
there are other functions... use code completion to see what else functions are available against series rendereing with name starting from lookupSeries........(int seriesindex)
I found a rather strange way to get the points without any lines connecting them.
I set the Stroke of the renderer to be a thin line, with a dash phase of 0, and length of 1e10:
Stroke dashedStroke = new BasicStroke(
0.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
0.0f, new float[] {0.0f, 1e10f}, 1.0f );
renderer.setSeriesStroke(0, dashedStroke);

Resources