How to convert extent from EPSG 3857 to EPSG 26331 - gis

I am trying to convert extent which is in 3857 projection into 26331 projection in OpenLayers by ol.proj.transformExtent(map.getView().calculateExtent(map.getSize()),'EPSG:3857','EPSG:26331')

You will first need to include the proj4js library
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.6.2/proj4.js"></script>
Then the EPSG:26331 proj4js definition from https://epsg.io/26331
proj4.defs("EPSG:26331","+proj=utm +zone=31 +ellps=clrk80 +towgs84=-92,-93,122,0,0,0,0 +units=m +no_defs");
ol.proj.proj4.register(proj4); // if you are using OpenLayers 5 or 6
var transformedExtent = ol.proj.transformExtent(map.getView().calculateExtent(map.getSize()),'EPSG:3857','EPSG:26331');

Related

How to to convert GPS coordinates from UTM SAD69 to decimal SIRGAS2000?

How would be the algorithm to convert the following GPS coordinates (Java language prefered)?
From UTM/SAD69:
Latitude: 7171359,145
Longitude: 716431,81
Zone: 22
Hemisphere: South
To Decimal (Google Maps friendly):
Longitude: -48.8461461196
Latitude: -25.559740724
http://maps.google.com.br/maps?q=-25.559740724,-48.8461461196&hl=pt-BR&t=h&z=16
You could utilize UTMConverter.java for that purpose, the following example:
double easting = 716431.81;
double northing = 7171359.145;
int zone = 22;
boolean isSouthHemishere = true;
LatLng value = UTMConverter.convertToLatLng(easting,northing,zone,isSouthHemishere);
System.out.println(value);
gives the same result (lat: -25.55933783,lng:-48.84565751) as Geographic/UTM Coordinate Converter online tool
Use PROJ.4 to convert from EPSG:29192 (SAD69 / UTM zone 22S) to EPSG:4326 (WGS 84).
For example here is a simple interface to transform, but there are others for command line, JavaScript, etc.

plotting maps using OSM or other shapefiles and matplotloib for standardized report

We are developing a standardized report for our activities. The last graph I need is to display the geographic area of the activities (there are close to 100 locations).
The output for these reports is PDF letter or A4 size
The report is a mplotlib figure, where:
fig = plt.figure(figsize=(8.5, 11))
rect0 = 0, .7,, 0.18, 0.3
rect1 = .3, .7, .18, .3
rect2 = .8, .29, .2, .7
rect3 = 0, 0, .8, .4
ax1 = fig.add_axes(rect0)
ax2 = fig.add_axes(rect1)
ax3 = fig.add_axes(rect2)
ax4 = fig.add_axes(rect3)
The contents and layout for axes 1-3 are settled and work great. However ax4 is where the map contents would be displayed (ideally).
I was hoping to do something like this:
map1 = Basemap(llcrnrlon=6.819087, llcrnrlat=46.368452, urcrnrlon=6.963978,
urcrnrlat=46.482906, resolution = 'h', projection='tmerc',
lon_0=6.88, lat_0=46.42, ax=4)
map1.readshapefile('a valid shape file that works') #<----- this is the sticking point
map1.draw(insert locator coordinates)
plt.savefig(report to be inserted to document)
plt.show()
However I have not been successful in obtaining a shape file that works from open street maps or GIS.
Nor have I identified the correct process to transform the data from openstreetmaps.
Nor have I identified the process to extract that information from the OSM/xml document or the transformed GeoJSON document.
Ideally I would like to grab the bounding box information from openstreetmaps and generate the map directly.
What is the process to get a shapefile that works with the .readshapefile() call?
Or alternatively how do I get the defined map into a Matplotlib axes ?
It might be easiest to use the cartopy.io.img_tiles module, which will automatically pull the OSM tiles for use with cartopy. Using the pre-rendered tiles would negate the trouble of handling and styling individual shapefiles/XML.
See the cartopy docs on using these tiles within cartopy.

Autodesk Forge Viewer : f2d get frag from dbid

I am trying to fill in room with color on a revit converted file's 2d viewer.
I have a Revit file that has "rooms" defined. The Revit file also has sheets defined "Floor one", "Floor two". When I convert it using the Forge API
I get a svf for the Revit 3D view and f2d files for "Floor one" and "Floor Two"
sheets.
For the svf I was able to get fragid from dbids other post
Now Im trying to do the same for the f2d files.
I am able to change the color of the room walls if I know the wall shapes dbid by using
viewer.setThemingColor(dbid, new THREE.Vector4(0, 1, 1,1));
What I want to do now is be able to get the fragid of the shape on 2d so that I can get the start and stop vertices of the lines it uses. I want to know these vertices so I can build a custom mesh and fill it in with color for room "hatching".
My problem is that I do not know the f2d format. It seems it is all one mesh and lets the shader control the color of the lines. Can anyone give me any pointers on how to the the fragment list of the room?
This is what I used for the 3d svf
function getFragIdFromDbId(viewer, dbid) {
var returnValue;
var it = viewer.model.getData().instanceTree;
it.enumNodeFragments(dbid, function (fragId) {
//console.log("dbId: " + dbid + " FragId : " + fragId);
returnValue = fragId;
}, false);
return returnValue;
}
What can I use for f2d to do the same when the f2d has viewer.model.getData().instanceTree = undefined?
Fragments can have geometry for multiple dbids and the geometry for a dbid can be in multiple fragments. It is possible to extract with Autodesk.Viewing.Private.VertexBufferReader, used by the 2D snapper that helps. You could do something like this:
FragmentList.dbid2fragId[dbid] will return the fragment id or an array of fragment ids that contain geometry for the dbid.
Loop through the fragments and get the geometry for each fragment.
Create a VertexBufferReader using the geometry.
Use the VertexBufferReader to find the geometry for a dbid.
The best way to find the geometry is to use VertexBufferReader.enumGeomsForObject(dbid, callback). It uses a callback object to enumerate geometry for a dbid. The callback object needs these optional functions:
onLineSegment(x0, y0, x1, y1, viewport_id)
onCircularArc(centerX, centerY, startAngle, endAngle, radius, viewport_id)
onEllipticalArccenterX, centerY, startAngle, endAngle, major, minor, tilt, viewport_id)
onTriangleVertex(x, y, viewport_id)
This is OK if you just need the primitives and not where they are in the buffer.
You can also use the VertexBufferReader to loop through the geometry in the buffer looking for the dbid. This requires you to know the a primitive in the vertex buffer is 4 vertices if .useInstancing() is false and 1 vertex if .useInstancing() is true. And you need to decode the primitive type from .getVertexFlagsAt(vertexIndex) but we don’t any public values or methods for decoding the flags.

Projection drift when rendering in WebGL over Google Map

I am trying to implement a WebGL-based rendering on Google Map (api3) as I want to render a massive amount of dynamic geometries.
Basically, I create a google.maps.OverlayView attached with a WebGL canvas into the map.
However, I encountered some problem with the mapping of the projection. Basically, I extracted the "fromLatLngToPoint" function from the googlemap api as follows:
function fromLatLngToPoint(a){
var c={x:0,y:0},
d=this.j;
c.x=d.x+a.lng*this.B;
var e=oe(m.sin(re(a.lat)),-(1-1E-15),1-1E-15);
c.y=d.y+.5*m.log((1+e)/(1-e))*-this.F;
return c
}
function oe(a,b,c){null!=b&&(a=m.max(a,b));null!=c&&(a=m.min(a,c));return a}
function re(a){return m.PI/180*a}
Then I implemented it in my vertex shader based on the documentation in Google Map Coordinates.
Basically, I have a event listener to send the updated projection constants, the viewport bounds, and the zoom level to my shader.
Then my shader will calculate the new screen coordinates based on these inputs.
highp float e, x, y, offsetY, offsetX;
// projection transformation for target points
e = sin(p.y* PI/180.0);
y = prj_y + 0.5 * log((1.0+e)/(1.0-e))*(-F);
x = prj_x + p.x*B;
// projection transformation for offset (bounds)
e = sin(bound_y*PI/180.0);
offsetY = prj_y + 0.5 * log((1.0+e)/(1.0-e))*(-F);
offsetX = prj_x + bound_x*B;
// calculate actual pixel coord wrt zoom/numTiles
x = (x* numTiles - offsetX* numTiles);
y = (y* numTiles - offsetY* numTiles);
gl_PointSize = 5.0;
gl_Position = projectionMatrix * modelViewMatrix * vec4(x,y,0.0,1.0);
However, as shown in the screenshot below, it seems there are some errors? The rendered geometries are distorted. (I used the google map polygon api to render some of the geometries as comparison)
Screenshot Here
I am totally at a loss, what might be the reason for this distortion?
I am suspecting that the single precision in the shader is giving rise to the error. So I am wondering if there is any workaround?
It is hard to debug this piece of code and diagnose the cause of the issue. I would suggest you using the CanvasLayer library that hides all these concrete details of specifying the coordinates you want to draw the polygon. Rather you would be able to focus on your app code and functionality. The performance will be better in terms of projected image.

Parse coordinates out of XML feed

Hello I hope I explain this correctly. I am trying to make polygons in Google Maps with coordinates from a XML feed. Problem is the cordinates in the XML feed as not shown as Lat Lon they are shown like this in the feed.
<cap:polygon>
29.66,-97.19 29.40,-97.24 29.11,-97.61 29.35,-97.85 29.57,-97.66 29.68,-97.36 29.66,-97.19
</cap:polygon>
So I need to parse the coordinates out of the XML feed, convert them into google.maps.LatLng objects, so I can push them into an array, so I can provide that array as the paths property in the google.maps.Polygon constructor.
Now this is where I am stuck as I am not sure how to go about parsing that feed element so they are properly formatted the way I need them so I can construct the polygons unless there is a way I can construct the polygons with the way it's formatted now.
Any suggestions or advice would be great!
-Thanks!
Get the content of that XML element into a string. Note that with the "cap" namespace you will have to write browser independent code (different browsers treat that differently).
split the string on spaces (" "):
var coordinates = polygonElemStr.split(" ");
split each set of coordinates on the comma (","), create a google.maps.LatLng from the two numbers and push it onto an array:
var path = [];
for (var i=0; i<coordinates.length; i++) {
var coord = coordinates[i].split(",");
path.push(new google.maps.LatLng(parseFloat(coord[0]),
parseFloat(coord[1])));
}
use that array of coordinates to create your polygon.
example