I styled a layer with uDig and exported the style as SLD file. I then applied the same style to the a layer (same shapefile) in my code using Geotools. However, uDig's rendering of the map looks much better than mine.
My project uses geotools version 21.2, Java 1.8 and I'm rendering the map with Geotools's JMapPane. Having noticed that the uDig version looks better that mine, I attempted digging into the uDig source to see how the shape files are rendered. I found that shape file are rendered in uDig by ShapefileFeatureRenderer, or so I think. I then copied and pasted the renderer's initialization code and applied it in my project but I didn't notice any difference.
renderer = new StreamingRenderer();
HashMap<String, Object> rendererHints = new HashMap<String, Object>();
rendererHints.put("optimizedDataLoadingEnabled", true); //$NON-NLS-1$
renderer.setRendererHints(rendererHints);
// renderer.removeRenderListener(StreamingRenderer.DEFAULT_LISTENER);
renderer.addRenderListener(listener);
// JG - these may be overriden by the preferences before use?
RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
renderer.setJava2DHints(hints)
mapPane.setRenderer(renderer);
How do I make my map rendering as good as uDig's (uDig's rendering is to the left in the screenshot below) ?
I would like some one to point me in the right direction on how to go about this. Any help would be appreciated.
I think you should leave the default renderer in place and simply add to it's hints, so something like:
renderer = frame.getMapPane().getRenderer();
Map<Object, Object> rendererHints = renderer.getRendererHints();
rendererHints.put("optimizedDataLoadingEnabled", true);
renderer.setRendererHints(rendererHints);
RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
renderer.setJava2DHints(hints);
If that doesn't do it then you might want to look at what hints the GeoServer render gets set, for example here
Related
I have successfully read an SVG file into an org.w3c.dom.Document to see its structure.
Now I'd like to render it to the screen using Java's AWT's Graphics2D.
Note:
I don't want to use Swing (e.g., with org.apache.batik.swing.JSVGCanvas).
All the Googling I do tells me how to write to an SVGGraphics2D. (Nifty; I use it elsewhere!)
But I don't want to do that; I want to draw to the screen.
Is there a way to do this?
Or are there lower-level Swing-independent drawing classes that JSVGCanvas uses internally to draw to an AWT graphics context?
I'd hoped to find simple, clear calls that took as parameters, e.g., a Graphics2D and a Document.
[Edit by OP: Unless I dreamt it--complete with cut-and-paste-able code--I got the answer in a comment within minutes... ; ) Here's its essence for others with the need, and so people don't waste time answering again:]
// Create a user agent and document loader
UserAgent userAgent = new UserAgentAdapter();
DocumentLoader loader = new DocumentLoader(userAgent);
// Create a bridge context and GVT builder
BridgeContext ctx = new BridgeContext(userAgent, loader);
ctx.setDynamic(true);
GVTBuilder builder = new GVTBuilder();
// Build the graphics node
GraphicsNode graphicsNode = builder.build(ctx, [Document]);
// Paint the graphics node to the Graphics2D object
graphicsNode.paint([Graphics2D]);
And without that comment the image I pasted of the result made the question meaningless/confusing; now may make sense. Thank you again to that moderator-deleted poster! (I think because he asked for college money...)
I'm trying to implement a custom barchart
which should look exactly like this. I tried mpChart but could only get this far
barDataSet = new BarDataSet(barEntries, "");
barData = new BarData(barDataSet);
barData.setBarWidth(.5f);
barChart.setData(barData);
barDataSet.setColors(getResources().getColor(R.color.colorPrimary));
barDataSet.setValueTextColor(Color.BLACK);
barDataSet.setDrawValues(false);
barChart.getXAxis().setDrawAxisLine(false);
barChart.setDrawGridBackground(false);
barChart.getXAxis().setDrawGridLines(false);
barChart.getAxisLeft().setDrawGridLines(false);
barChart.getAxisRight().setDrawGridLines(false);
barChart.getAxisLeft().setEnabled(false);
barChart.getAxisRight().setEnabled(false);
barChart.getLegend().setEnabled(false);
barChart.setPinchZoom(false);
barChart.setDescription(null);
barChart.setTouchEnabled(false);
barChart.setDoubleTapToZoomEnabled(false);
barChart.setExtraOffsets(20, 0, 0, 30);
XAxis xAxis = barChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setTextSize(14f);
xAxis.setTextColor(Color.BLACK);
xAxis.setYOffset(5);
xAxis.setDrawLabels(true);
xAxis.setGranularityEnabled(true);
xAxis.setGranularity(1f);
xAxis.setXOffset(30);
xAxis.setValueFormatter(new IndexAxisValueFormatter(xAxisLabel));
xAxis.setCenterAxisLabels(true);
barChart.invalidate();
I tried almost all possible examples and questions here, couldn't get the label to centre of the bars. Is it possible to put the labels exactly below the bars in non grouped bars? all the solutions I saw is only for grouped bars or combined charts.
I was plotting the x axis values from 1. when changed it to 0 and removed
xAxis.setCenterAxisLabels(true);
and i was able to centre the axis labels
You need to create a custom renderer for it.
Subclass BarChartRenderer and then call:
barChart.setRenderer(new MyBarChartRenderer(barChart, barChart.getAnimator(), barChart.getViewPortHandler()))
It will even allow you to alter the shape of it as described here.
But I think what you're looking for comes really close to this.
Download the MPAndroidChart Source from here. Then, you can customize the code according to your need and add it your project by
Clicking on File>New>Import Module.
I'm trying to resize and crop an image using ImageJ. Here's the code:
ImagePlus ip1 = IJ.openImage("_Pic.jpg");
ImagePlus ip2 = IJ.openImage("_Pic.jpg");
ImageProcessor imgP1 = ip1.getProcessor();
ImageProcessor imgP2 = ip2.getProcessor();
FileSaver fs1 = new FileSaver(ip1);
FileSaver fs2 = new FileSaver(ip2);
/* Trying to resize */
imgP1.resize(100); // also tried with width and height
fs1.saveAsJpeg("Resized.jpg");
/* Trying to crop */
imgP2.setRoi(100, 100, 200, 200);
imgP2.crop();
fs2.saveAsJpeg("Cropped.jpg");
Unfortunately, the newly created files are identical to the original one.
So far I've found out how to blur, smooth, invert, translate, rotate, ..., but these two are giving me hard time. Anybody has an idea?
Your cross-posted question to the ImageJ forum was answered there by Stefan Helfrich:
If you take a look at the Javadocs for ImageProcessor you'll see that resize() as well as crop() return new ImageProcessor instances and do not operate on this. That's why you'll have to use the ImagePlus.setProcessor(ImageProcessor) method to add the returned ImageProcessors to ip1 and ip2.
When cross-posting like this, please always include links to the other posts, so people finding this question later will have a chance to follow the discussion.
circle crop: https://youtu.be/OyiOFh1pD3k
resize: https://youtu.be/N_jddMMhzqc
combine both code.
To my immense surprise, it seems impossible to find any other people having this problem -- I can use Jmonkey to import a mesh (in my case a gear), but it doesn't properly map the texture (which is supposed to look like wood), only texturing a few select faces shown:
It still looks fine in Blender:
To summarize, how do I get the texture to map over the ENTIRE gear, not just some triangles?
My code is written like this (pardon if it's a little messy, I've been trying to solve this for a while now):
Spatial gear = assetManager.loadModel("Models/cog_3.j3o");
//Geometry geargeo=(Geometry)gear;
//Node gearnode = (Node)gear;
//Mesh gearmesh = (Mesh) gearnode;
//Mesh gearmesh = (Geometry)(gearnode.getChildren().get(0));
TangentBinormalGenerator.generate(gear);
Material wood = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
Texture woodtex = assetManager.loadTexture("Textures/wood-texture.jpg");
woodtex.setWrap(Texture.WrapMode.Repeat);
wood.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);
wood.setTexture("ColorMap", woodtex);
wood.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
gear.setMaterial(wood);
rootNode.attachChild(gear);
My mesh looks like this (you can see the uv seams):
Uv looks like this:
I'm using blender 2.78a,
and (as far as I know), the latest version of JME.
Any help is appreciated greatly.
I created a simple model of a barrel (.zip) in Blender 2.69. Then I created a UV map in Blender and made a UV mapped texture out of it (its in the archive, too). Then I imported my texture in Blender, now the mapping matches:
In Blender the model looks fine so far:
By using the Ogre exporter plugin that I installed via the jmonkeyengine SDK, I exported the model. The result of this is my OgreXML format file of the barrel (I did not export material).
Now, I tried to add the barrel to my world like this:
this.barrel = this.assetManager.loadModel("models/barrel/Barrel.mesh.xml");
Material barrelMat = new Material(this.assetManager,
"Common/MatDefs/Light/Lighting.j3md");
barrelMat.setTexture("DiffuseMap",
this.assetManager.loadTexture("models/barrel/Barrel.jpg"));
barrelMat.setBoolean("UseMaterialColors", true);
barrelMat.setColor("Diffuse", ColorRGBA.White);
barrelMat.setColor("Specular", new ColorRGBA(0.3f, 0.1f, 0, 1));
barrelMat.setFloat("Shininess", 4f);
this.barrel.setMaterial(barrelMat);
this.rootNode.attachChild(this.barrel);
The result is this:
Is there something else I have to consider when setting the texture for my UV mapped model?
Often when transferring models from Blender to something like JME, the textures will be upside down. Where you load the texture:
barrelMat.setTexture(“DiffuseMap”,
assetManager.loadTexture(“models/barrel/Barrel.jpg”));
Instead use the TextureKey form of the loadTexture() method and pass yFlip false since true is the default.
assetManager.loadTexture(new TextureKey(“models/barrel/Barrel.jpg”, false));
That should fix your issue.
References:
loadTexture() : http://hub.jmonkeyengine.org/javadoc/com/jme3/asset/AssetManager.html#loadTexture(com.jme3.asset.TextureKey)
TextureKey : http://hub.jmonkeyengine.org/javadoc/com/jme3/asset/TextureKey.html#TextureKey(java.lang.String,%20boolean)