Projection of a SpatialPixelsDataFrame objects - map-projections

I have created SpatialPixelsDataFrame objects from Raster files. But I cannot work it along with my SpatialPintsDataFrame object. I got this error message:
Error in count.points(GPSLocs, Grass) : different proj4string in w and xy
which means the SpatialPixelsDataFrame objects do not have a projection defined.
GPSLocs= SpatialPointsDataFrame object
Grass= SpatialPixelsDataFrame object
Any suggestions of how to fix this issue?

The message "different proj4string in w and xy" suggest that the coordinate reference systems are different (it may be that one of them is undefined). For others to be able to help you, should always show some code or data. For example what you get when you do:
library(raster)
w
xy
# or
crs(w)
crs(xy)

Related

Figuring out coordinate format contained in SDO_ORDINATE_ARRAY attribute

I am working with some data which specifies an installation path, in another data source I have the location of events based on their lat/long location.
The installation location contained in the oracle attribute SDO_ORDINATE_ARRAY does not match any X/Y geographic coordinate system I am familiar with (Lat/Long or UTM). Is there a way to figure out what the data type is that is stored in the SDO_ORDINATE_ARRAY?
Here is an example of the data for a path with 3 (x,y) points:
MDSYS.SDO_GEOMETRY(2002,1026911,NULL,
MDSYS.SDO_ELEM_INFO_ARRAY(1,2,1),
MDSYS.SDO_ORDINATE_ARRAY(
1352633.64991299994289875030517578125,
12347411.6615570001304149627685546875,
1352638.02988700009882450103759765625,
12347479.02890899963676929473876953125,
1352904.06293900008313357830047607421875,
12347470.76137300021946430206298828125,
))
The above should be roughly within the proximity to 33.9845° N, 117.5159° W, and I went through various conversions but could not find anything that led me anywhere close to the above.
I read through the documentation on SDO_GEOMETRY from the oracle page and did not find any help in figuring out what the data type is.
https://docs.oracle.com/database/121/SPATL/sdo_geometry-object-type.htm#SPATL494
Alternatively, if there is a way I can type in the lat/long somewhere to see all of the different coordinate types which are equivalent, I might also be able to figure out which format this is.
Looks like there is a typo inside MDSYS.SDO_GEOMETRY(2002,1026911,NULL,
1026911 is supposed to be a SRS - Spatial Reference System.
If we remove the first 1 we have 102691, and that is a very well known SRS code.
ESRI:102691 for NAD 1983 for StatePlane Minnesota North FIPS 2201 Feet
The corresponding WKT gives you all the necessary information to perform any coordinate conversion:
PROJCS["NAD_1983_StatePlane_Minnesota_North_FIPS_2201_Feet",
GEOGCS["GCS_North_American_1983",
DATUM["North_American_Datum_1983",
SPHEROID["GRS_1980",6378137,298.257222101]],
PRIMEM["Greenwich",0],
UNIT["Degree",0.017453292519943295]],
PROJECTION["Lambert_Conformal_Conic_2SP"],
PARAMETER["False_Easting",2624666.666666666],
PARAMETER["False_Northing",328083.3333333333],
PARAMETER["Central_Meridian",-93.09999999999999],
PARAMETER["Standard_Parallel_1",47.03333333333333],
PARAMETER["Standard_Parallel_2",48.63333333333333],
PARAMETER["Latitude_Of_Origin",46.5],
UNIT["Foot_US",0.30480060960121924],
AUTHORITY["EPSG","102691"]]

MATLAB ConnectedComponentLabeler does not work in for loop

I am trying to get a set of binary images' eccentricity and solidity values using the regionprops function. I obtain the label matrix using the vision.ConnectedComponentLabeler function.
This is the code I have so far:
files = getFiles('images');
ecc = zeros(length(files)); %eccentricity values
sol = zeros(length(files)); %solidity values
ccl = vision.ConnectedComponentLabeler;
for i=1:length(files)
I = imread(files{i});
[L NUM] = step(ccl, I);
for j=1:NUM
L = changem(L==j, 1, j); %*
end
stats = regionprops(L, 'all');
ecc(i) = stats.Eccentricity;
sol(i) = stats.Solidity;
end
However, when I run this, I get an error says indicating the line marked with *:
Error using ConnectedComponentLabeler/step
Variable-size input signals are not supported when the OutputDataType property is set to 'Automatic'.'
I do not understand what MATLAB is talking about and I do not have any idea about how to get rid of it.
Edit
I have returned back to bwlabel function and have no problems now.
The error is a bit hard to understand, but I can explain what exactly it means. When you use the CVST Connected Components Labeller, it assumes that all of your images that you're going to use with the function are all the same size. That error happens because it looks like the images aren't... hence the notion about "Variable-size input signals".
The "Automatic" property means that the output data type of the images are automatic, meaning that you don't have to worry about whether the data type of the output is uint8, uint16, etc. If you want to remove this error, you need to manually set the output data type of the images produced by this labeller, or the OutputDataType property to be static. Hopefully, the images in the directory you're reading are all the same data type, so override this field to be a data type that this function accepts. The available types are uint8, uint16 and uint32. Therefore, assuming your images were uint8 for example, do this before you run your loop:
ccl = vision.ConnectedComponentLabeler;
ccl.OutputDataType = 'uint8';
Now run your code, and it should work. Bear in mind that the input needs to be logical for this to have any meaningful output.
Minor comment
Why are you using the CVST Connected Component Labeller when the Image Processing Toolbox bwlabel function works exactly the same way? As you are using regionprops, you have access to the Image Processing Toolbox, so this should be available to you. It's much simpler to use and requires no setup: http://www.mathworks.com/help/images/ref/bwlabel.html

Conversion lambert to WGS84 (Geocoding + Oracle Locator)

I'm currently tying to geocode addresses in Austria. From a given postal code and street etc. I want to automatically find latitude and longitude in WGS84 format. My first approach was to use a webservice like OpenStreetMaps Nominatim. Actually this gives decent results.
Still it is mandatory to use a disk with addresses (PAC) and their respective geolocation as a ground truth. Only if I'm not able to match the address within this data I can use the web service approach as a backup solution.
So much for context, now the problem:
On this disk the gelocation is given as X_LAMBERT and Y_LAMBERT and I can't quite figure out how to convert into latitude+longitude.
The diks's data is loaded into an Oracle 11g database with Locator and I'm doing the following:
Step 1:
Creation of spatial geometry object: MDSYS.SDO_GEOMETRY(2003,31287,NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1), MDSYS.SDO_ORDINATE_ARRAY(X_LAMBERT,Y_LAMBERT))
Step 2: Projection from WGS84 to LatLng:
SDO_CS.TRANSFORM( GEOMETRY, 4326) in my Java client I obtain latitude, longitude from the geometry via oracle.spatial.geometry.JGeometry.
Note:
I suspect 31287 to be SRID of the lambert format, I tried 8307 and 3416, but latter give even worse results.Step 2 works fine with other geometry objects, where I know the correct SRID for sure... so I guess the error is somewhere in Step 1.
Do I have to set something in USER_SDO_GEOM_METADATA ? Wrong usage of SDO_GEOMETRY constructor ? Am I still mixing up datum and projection? Maybe you can enlighten me there aswell...
The result of my action and example for input are:
Input: X_LAMBERT 602823, Y_LAMBERT 464397
Resulting Output: WGS84 (48.0469757028535, 16.0542604612583)
Expected Output: WGS84 (48.546363, 16.085735)
Its like almost correct, but still some 100 kilometers off ;-)

Hand-Generated TopoJSON not Parsing

I wrote a simple function to parse a the results of d3.geom.voronoi into topoJSON format, which you can see here:
http://bl.ocks.org/emeeks/9908143
As far as I can tell, it matches up with the topoJSON generated in http://bl.ocks.org/mbostock/5249328 except that it doesn't use translate or scale (though I've generated it with a translate of (0,0) and a scale of (1) and received the same error). When I try to parse the features with topojson, I receive this error:
TypeError: Cannot read property 'length' of undefined
at arc (topojson.js:172:54)
at line (topojson.js:187:52)
at ring (topojson.js:193:20)
at Array.map (native)
at polygon (topojson.js:199:19)
at Object.geometryType.Polygon (topojson.js:214:37)
at geometry (topojson.js:205:71)
at object (topojson.js:218:12)
at feature (topojson.js:160:17)
at topojson.js:151:55
The Polygon example I based this on has an array of arrays for arcs, whereas the Linestring example I've compared it to has an array of arcs, so my assumption is that the Polygon by default is a multipolygon and I've followed the array of arrays for this example, but if I just make an array of arcs, it gives me the error "cannot call slice of undefined".
I'm pretty sure my vorToPoly function is mapping arcs correctly, but if someone could take a look at my object topoCollection (I've echoed it to the console) and tell me how it's not matching up with what topojson expects, I'd appreciate it.
Mike Bostock pointed out that the error occurred because my topojson collection was referring to an arc that didn't exist because it started counting the arcs at 1 instead of 0. The problem occurred in this part of my vorToPoly code:
topoArcs.push([[Math.floor(vorPolys[x][y][0]),Math.floor(vorPolys[x][y][1])],[Math.floor(vorPolys[x][nextVal][0]),Math.floor(vorPolys[x][nextVal][1])]]);
arcHash[hashVal] = topoArcs.length;
It should have been flipped:
arcHash[hashVal] = topoArcs.length;
topoArcs.push([[Math.floor(vorPolys[x][y][0]),Math.floor(vorPolys[x][y][1])],[Math.floor(vorPolys[x][nextVal][0]),Math.floor(vorPolys[x][nextVal][1])]]);
That way the hash is starting at 0 instead of 1. Flipping this makes everything work just fine.

Loading OBJ file in three.js

I was trying to visualize a simple 3D model of the cylinder on the browser by importing OBJ file in three.js. I started with running simple example of three.js's OBJ loader:
https://github.com/mrdoob/three.js/blob/master/examples/webgl_loader_obj.html
which works fine locally.
I tried just by replacing the path of OBJ file with that of mine, but it failed to load. I double check the Path and it is correct.
On checking errors on the console on Firefox (Crtl + Shift + k), it says: Syntax Error and throws following error:
[22:59:30.865] Error: WebGL: DrawElements: bound vertex attribute buffers do not have sufficient size for given indices from the bound element array # http://localhost/~harmanpreet/three.js/build/three.min.js:455
The OBJ file is converted from model made in BRL-CAD (.g to .obj conversion). Link to OBJ file: http://devplace.in/~harman/cyl1_bot_dump.obj
Can anybody figure out what is the problem?
Thank you
Your .obj file looks correct according to specs, but I would advise you to use a non-minified three.js version and then look at the code surrounding the error message.
Also what you could try is replacing the "g" in the obj file at start with an "o" (g = group, o = object) - I'm not sure how three.js handles this internally or if it makes a difference, but I guess it won't hurt to try.
Other than that the error seems to be saying something like "I encountered an array index which is out of bounds", meaning a face (f in the .obj file) uses an index which is higher than the highest defined index, but that doesn't seem to be the case with your file (.obj indexes start at 1, so everything should be fine).

Resources