I get a .png from my server that represents a satellite image and I would put this image like a layer over the OpenStreetMap so I can see the street (under the satellite image) and the aerial photo on the same map.
I use this method
Drawable d = new BitmapDrawable(getResources(), bitmap);
bb = map.getBoundingBox();
Location SO = new Location(LocationManager.GPS_PROVIDER);
SO.setLatitude(bb.getLonWest());
SO.setLongitude(bb.getLatSouth());
Location NO = new Location(LocationManager.GPS_PROVIDER);
NO.setLatitude( bb.getLonWest());
NO.setLongitude(bb.getLatNorth());
Location NE = new Location(LocationManager.GPS_PROVIDER);
NE.setLatitude(bb.getLonEast());
NE.setLongitude(bb.getLatNorth());
float height = SO.distanceTo(NO);
float width = NE.distanceTo(NO);
Projection projection = map.getProjection();
int y = map.getHeight() / 2;
int x = map.getWidth() / 2;
GeoPoint geoPoint = (GeoPoint) projection.fromPixels(x, y);
deleteLayers(GroundOverlay.class);
GroundOverlay myGroundOverlay = new GroundOverlay();
myGroundOverlay.setImage(d);
myGroundOverlay.setPosition(geoPoint);
myGroundOverlay.setDimensions(width*0.94f, height*1.06f);
map.getOverlays().add(myGroundOverlay);
map.invalidate();
the problem is that the image always is stretch. my png cover only a part of my map (and it's ok beacuse our png is this way). When i move in the map the image stretching in all map but and it cover a part of map that it not rappresent.
Also, the image is not in the right place (look the red arrow).
How can i fix it?
Assuming your satellite image is limited to a portion of map you can use osmbonuspack GroundOverlay.
Probably this issue: https://github.com/MKergall/osmbonuspack/issues/273
Look at the hint about corrective coefficients.
Related
The Heatmap Overlay for the Android Google Maps API renders the radius in pixels, which means that by zooming in and out the radius gets bigger and smaller.
I need a heatmap with fixed radius (e.g. in meters instead of pixels) that does not rescale when zooming in and out.
Is there any possibility to do so?
In googlemap api, get scale data. In UI you have the legend which states the map scale. Something like this - (check in google maps bottom right I'm talking about 2000Ft thing below)
You know cm length of the phone screen, you know the pixels in complete width,so
cm(phoneScreen) --> cm/pixel ratio --> pixel radius to cm radius.
you can deduce using some maths I suppose.
As for my opinion you can use setRadius() method to change the radius of heatmaps location in response to changed zoom. Something like this:
int DEFAULT_ZOOM_LEVEL = 10;
int ZOOM_STEP_FOR_RADIUS = 2;
mProvider = new HeatmapTileProvider.Builder()
.data(mList)
.setRadius(DEFAULT_ZOOM_LEVEL)
.build();
mOverlay = mMap.addTileOverlay(new TileOverlayOptions().tileProvider(mProvider));
mMap.setOnCameraIdleListener(new GoogleMap.OnCameraIdleListener({
#Override
void onCameraIdle() {
float newZoom = mMap.getCameraPosition().zoom;
mProvider.setRadius(DEFAULT_ZOOM_LEVEL + newZoom * ZOOM_STEP_FOR_RADIUS)
mOverlay.clearTileCache();
}
});
I have following pdf with crop box as shown below
Rotated the page to make it horizontal using below code
PDPageContentStream cs = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false, false);
PDRectangle cropBox = page.getCropBox();
float tx = (cropBox.getLowerLeftX() + cropBox.getUpperRightX()) / 2;
float ty = (cropBox.getLowerLeftY() + cropBox.getUpperRightY()) / 2;
cs.transform(Matrix.getTranslateInstance(tx, ty));
cs.transform(Matrix.getRotateInstance(Math.toRadians(5), 0, 0));
cs.transform(Matrix.getTranslateInstance(-tx, -ty));
cs.close();
The result from above code is
Since coordinates has been changed after affine transformation, for old crop box coordinates i am getting different section. I want to get the original section which i had pointed before rotation.
So,I have tried following techniques to get new coordinates, but didn't get the result
double x_transformed = (x*Math.cos(angle))-(y*Math.sin(angle));
double y_transformed = (x*Math.sin(angle))+(y*Math.cos(angle));
double X_transformed = (X*Math.cos(angle))-(Y*Math.sin(angle));
double Y_transformed = (X*Math.sin(angle))+(Y*Math.cos(angle));
Please suggest me solutions from which i can exactly crop the required section.
The data provided in the question is for reference only.Actual input files can get from below link :
drive.google.com/open?id=0BxPYWA8sfqTDVmY5YVQyZTZwSTA
Thanks in advance.
The issue is that you rotated the page around the center of the original crop box of the page (which defaults to the media box):
PDRectangle cropBox = page.getCropBox();
float tx = (cropBox.getLowerLeftX() + cropBox.getUpperRightX()) / 2;
float ty = (cropBox.getLowerLeftY() + cropBox.getUpperRightY()) / 2;
and thereafter you restrict to your new crop box:
int x = 39;
int y = 450;
int x2 = 360;
int y2= 500;
page.setCropBox(new PDRectangle(new BoundingBox((int)x, (int)y,(int)x2, (int)y2)));
In your previous question your task was to keep the center of the page crop box fixed and rotate everything around it. Thus, there it was correct to calculate the tx and ty from the page crop box.
Your task now, on the other hand, is to keep the center of the box fixed to which you eventually want to crop the page.
Thus, you now have to calculate tx and ty using the corners of that other box:
float tx = (x + x2) / 2;
float ty = (y + y2) / 2;
Alternatively you can simply change the order and first crop the page to the box between (x,y) and (x2,y2) and then rotate around the center of the changed crop box.
Yet another option would be to change the new crop box coordinates by the vector its center has been moved by the rotation.
Trying to resize a bitmap and set to a specific part of an imageview. The imageview is square and I wish to have the bitmap in the bottom right corner. Width to be 10% of imageview and height to be 30%.
int w = imageview.getWidth();
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.vertical_bar_green);
imageview.setImageBitmap(Bitmap.createScaledBitmap(bm, w/10, w*30/100, false));
imageview.setScaleType(ScaleType.FIT_END);
The result is the bitmap is the full height of the imageview and the width is much larger.
How can I set specific points to place the bitmap?
From the documentation for END (the matrix used by FIT_END).
Compute a scale that will maintain the original src aspect ratio, but
will also ensure that src fits entirely inside dst. At least one axis
(X or Y) will fit exactly. END aligns the result to the right and
bottom edges of dst.
You will probable want to use a custom matrix for this, probably built with setRectToRect().
For example:
Matrix matrix = new Matrix();
RectF from = new RectF(0, 0, bm.getIntrinsicWidth(), bm.getIntrinsicHeight());
RectF to = new RectF(view.getWidth() * 0.9, view.getHeight() * 0.7, view.getWidth(), view.getHeight());
matrix.setRectToRect(from, to, Matrix.ScaleToFit.FILL);
view.setScaleType(ScaleType.MATRIX);
view.setImageMatrix(matrix);
(I'm not sure if you wanted to keep the original proportions or not, if you want it then use FIT_END for setRectToRect()).
I have drawn an path in my canvas. On Single tap I want to resize the path. Say I want to make it double the original size.
I have tried path.transform but it shifts the path to a different location in canvass. This is the code I used for that
Matrix translateMatrix = new Matrix();
translateMatrix.setTranslate(100,0);
p.transform(translateMatrix);
How can I resize a path in android?
I have tried the solution provided by smitalm. Still the path was shifting its location. I have tried this way and it worked for me.
Matrix scaleMatrix = new Matrix();
RectF rectF = new RectF();
path.computeBounds(rectF, true);
scaleMatrix.setScale(1.25f, 1.25f,rectF.centerX(),rectF.centerY());
path.transform(scaleMatrix);
Havent done this by myself, but you should probably use
Matrix scaleMatrix = new Matrix();
scaleMatrix.setScale(sx,sy, px, py);
p.transform(scaleMatrix);
where sx,sy should be 2,2 in your case, if you want double size
and px,py should probably be 0.5,0.5 in your case
RectF bounds = new RectF();
path.computeBounds(bounds, true);
Matrix scaleMatrix = new Matrix();
scaleMatrix.setScale(scale_pathSX, scale_pathSY,
bounds.centerX(),bounds.centerY());
path.transform(scaleMatrix);
The Bound.centerx and center Y will help you to scale the path to its center position, scale_pathSX and scale_pathSY is for how much you want to scale your path,
FOR SCALE LARGE
scale_pathSX and scalepathSy = 1.001; FOR SCALE SMALL scale_pathSX and scalepathSy = 0.999;
I'm making application in java swing with netbeans platform. In my app I rotate MyImage.tiff (16 bit, tiff, Gray-Scale Image) it rotate image but change the type of MyImage.tiff. Before rotate image myImage.tiff type is 11, but after rotate MyImage.tiff it type change and it becomes 0 type of BufferedImage. So how to solve this Problem. In my app I use JAI for rotate image.I not installed JAI in my PC, but I made wrapper module in which I used jar files of JAI. So are there any missing jar files? My code for rotate Image is below.
public BufferedImage rotateRighteImage(BufferedImage im) {
int value = 90;
float angle = (float) (value * (Math.PI / 180.0F));
ParameterBlock pb = new ParameterBlock();
pb.addSource(im); // The source image
pb.add(0.0F); // The x origin
pb.add(0.0F); // The y origin
pb.add(angle); // The rotation angle
// Create the rotate operation
RenderedOp create = JAI.create("Rotate", pb, null);
im = create.getAsBufferedImage();
return im;
}