How to create fishnet in arcgis engine? - arcgis

I found createfishnet method in arcobject, but it doesn't work.Where is my mistake?
Geoprocessor gp = new Geoprocessor();
gp.OverwriteOutput = true;
ESRI.ArcGIS.DataManagementTools.CreateFishnet fishnet = new ESRI.ArcGIS.DataManagementTools.CreateFishnet();
fishnet.template = buffer_out;
//txtOutputPath2.Text="E:\\program\\shenzhen_science_committee\\sc\\landuse_subway\\shenzhen_subway\\23_net.shp"
fishnet.out_feature_class = txtOutputPath2.Text;
IFeatureCursor cursor1=buffer_out.Search(null,true);
IFeature buffer=cursor1.NextFeature();
IPoint centerPoint =new ESRI.ArcGIS.Geometry.Point();
IArea pArea = buffer.Shape as IArea;
pArea.QueryCentroid(centerPoint);
fishnet.origin_coord = centerPoint;
double height=0;
double width=0;
fishnet.cell_height = 0.1;
fishnet.cell_width = 0.1;
fishnet.number_columns = 50;
fishnet.number_rows = 50;
IGeoProcessorResult results = (IGeoProcessorResult)gp.Execute(fishnet, null);
The result shows wrong HRESULT E_FAIL.

I have tried this in ArcObjects with Java. What I found was that the fishnet could not be generated for area within a particular polygon, as in the ArcMap application. You would have to intersect or use spatial filter on the fishnet output.
Also, try giving all the parameters, even the optional ones like set corner coordinate. If you are using data in a particular projection system, that can be set to the output by setting the template (and this takes only Envelope).
Below is the code that I have used. I wanted the fishnet label as well, so I have enabled it. Make sure you use a space between the x and y coordinate of a point, entered as a String, which is probably the issue here.
GeoProcessor gp = new GeoProcessor();
gp.setOverwriteOutput(true);
IEnvelope aoi = buffer_out.getEnvelope();
CreateFishnet createFishnet = new CreateFishnet();
createFishnet.setOutFeatureClass(tempDir+"/"+fishnetOutput+".shp");
createFishnet.setTemplate(aoi);
createFishnet.setOriginCoord(aoi.getXMin()+" "+aoi.getYMin());
createFishnet.setYAxisCoord(aoi.getXMin()+" "+aoi.getYMax());
createFishnet.setCornerCoord(aoi.getXMax()+" "+aoi.getYMax());
createFishnet.setCellHeight(30.0);
createFishnet.setCellWidth(30.0);
createFishnet.setNumberRows(0);
createFishnet.setNumberColumns(0);
createFishnet.setLabels("LABELS");
createFishnet.setGeometryType("POLYLINE");
gp.execute(createFishnet, null);
I hope you can use this example and apply it to your code.

Related

GameMaker 2: Cannot use function/script name for a variable, using "_dir"

after going through the Space Mods - GML - Enemy Factions (2/3) - GameMaker Studio 2 tutorial on YouTube by Gamemaker.
I've came into some trouble with testing the game.
My compile error goes like this:
Script:create_bullet at line 6; cannot use function/script name for a variable, using "_dir"
The script in question:
/// #description create_bullet
/// #arg direction
/// #arg speed
/// #arg faction
function create_bullet(_dir,_spd,_fac,_creator){
var _dir = argument[0];
var _spd = argument[1];
var _fac = argument[2];
var _creator = self;
audio_play_sound(snd_zap, 1, false);
var inst = instance_create_layer(x,y, "Instances", obj_bullet);
with(inst){
direction = _dir();
speed = _spd;
faction = _fac;
creator = _creator;
if(faction == factions.ally) image_blend = c_aqua;
else if(faction == factions.enemy) image_blend = c_red;
}
}
I've checked the comments to see if anyone else has had a similar problem and I can't find the solution myself. Will anyone be able to help and explain. I'm quite new to coding and just taking it step by step.
I found an answer in another forum.
My mistake seems to have been placing brackets after _dir;:
with(inst){
direction = _dir(); <=
speed = _spd;
faction = _fac;
creator = _creator;
After removing that and taking out the var before:
_dir = argument[0];
_spd = argument[1];
_fac = argument[2];
_creator = self;
It seems to work fine now.

Cannonjs move body forward according to its quaternion

I'm struggling with Cannonjs physics lib, I got a sphere body with a changing quaternion, I just want that body to move forward according to its quaternion. I found many topics related to that but none of the suggested codes is working.
Is it a simple way to achieve that simple task?
So far I tried the solution given here but the using of vmult() method do not change the vector3 at all...
body.quaternion = new CANNON.Quaternion(0,1,0,0); // Whatever value you put here will not change the result of the vmult() operation below
var localVelocity = new CANNON.Vec3(0, 0, 1);
var worldVelocity = body.quaternion.vmult(localVelocity); //-> worldVelocity = (0,0,1)
body.velocity.copy(worldVelocity);
Try to set and not copy the body.velocity, this way:
let directionVector = new CANNON.Vec3(0, 0, 1);
directionVector.z -= moveDistance;
directionVector = vehicleBody.quaternion.vmult( directionVector );
vehicleBody.velocity.set( directionVector.x, directionVector.y, directionVector.z );

QGroupBox sizing with my QT5 custom widget

I am trying to make a custom widget: for displaying a processor register which has a name, a value and can be displayed in octal/decimal hexa. The code is shown at the bottom. I receive better result when I use the code as shown (i.e I insert QRadioButtons):
If I use
mainLayout->addWidget(DisplayMode);
instead (I guess this is the correct method) then the resulting picture is
Do I misunderstand something? What is wrong?
RegisterWidget::RegisterWidget(QWidget *parent)
:QFrame (parent)
{
mValue = 0;
mName = "";
setFrameStyle(QFrame::Panel | QFrame::Sunken);
QHBoxLayout *mainLayout = new QHBoxLayout(this);
label = new QLabel(tr("mName"),this);
label->setText(mName);
label->setLineWidth(2);
QGroupBox *DisplayMode = new QGroupBox("");
QRadioButton *OctalR = new QRadioButton(this);
QRadioButton *DecimalR = new QRadioButton(this);
DecimalR->setChecked(true); DecimalR->setDown(true);
QRadioButton *HexaR = new QRadioButton(this);
QHBoxLayout *hbox = new QHBoxLayout;
hbox->addWidget(OctalR);
hbox->addWidget(DecimalR);
hbox->addWidget(HexaR);
hbox->addStretch(1);
DisplayMode->setLayout(hbox);
mainLayout->addWidget(label);
Value = new QLCDNumber(this);
Value->setDigitCount(8);
Value->setSegmentStyle(QLCDNumber::Flat);
Value->display(mValue);
mainLayout->addWidget(Value);
/* mainLayout->addWidget(DisplayMode);*/
mainLayout->addWidget(OctalR);
mainLayout->addWidget(DecimalR);
mainLayout->addWidget(HexaR);
setLineWidth(3);
setLayout(mainLayout);
connect(OctalR, SIGNAL(clicked()), this, SLOT(setOctal()));
connect(DecimalR, SIGNAL(clicked()), this, SLOT(setDecimal()));
connect(HexaR, SIGNAL(clicked()), this, SLOT(setHexa()));
}
Call QLayout::setContentsMargins() for both mainLayout and hbox. Try (3, 3, 3, 3) as parameters for a starting point and tweak. Layouts have default margins of 11 pixels on most platforms, according to the docs.

PdfSharp: Text height/positioning problem

Whether I use XTextFormatter or not, I get the same error about the LayoutRectangle having to have a height of 0 or something like this.
new PdfSharp.Drawing.Layout.XTextFormatter(_gfx).DrawString(text
, new PdfSharp.Drawing.XFont(fontName, fontSize, (PdfSharp.Drawing.XFontStyle)fontStyle)
, new PdfSharp.Drawing.XSolidBrush(PdfSharp.Drawing.XColor.FromArgb(foreColour))
, new PdfSharp.Drawing.XRect(new PdfSharp.Drawing.XPoint(xPos, yPos), new PdfSharp.Drawing.XPoint(xLimit, yLimit))
, PdfSharp.Drawing.XStringFormats.Default);
fontStyle is of type System.Drawing.FontStyle
foreColour is of type System.Drawing.Color
I have already predefined _gfx from a PdfPage with Orientation = Landscape, Size = Letter
xPos and yPos are parameters of type double, the same with xLimit and yLimit.
I get the runtime error that the
LayoutRectangle must have a height of
zero (0)...
Per definition a rectangle is meant to have a height, otherwise call it a line! I don't get it!...
I tried with the XGraphics.DrawString() method directly, and I get the same error. It seems that I can't use the LayoutRectangle but have to manage that the text fit within the desired area manually.
var textFont = new PdfSharp.Drawing.XFont(fontName, fontSize, (PdfSharp.Drawing.XFontStyle)fontStyle);
while (xPos + _gfx.MeasureString(text, textFont).Width > xLimit)
textFont = new PdfSharp.Drawing.XFont(fontName, --fontSize, (PdfSharp.Drawing.XFontStyle)fontStyle);
while (yPos + _gfx.MeasureString(text, textFont).Height > yLimit && fontSize > 0)
textFont = new PdfSharp.Drawing.XFont(fontName, --fontSize, (PdfSharp.Drawing.XFontStyle)fontStyle);
_gfx.DrawString(text
, textFont
, new PdfSharp.Drawing.XSolidBrush(PdfSharp.Drawing.XColor.FromArgb(foreColour))
, new PdfSharp.Drawing.XPoint(xPos, yPos));
Though the yPos variable value is the exact same value!
*yPos = Page.Height * .4093, either 40,93% of the page's height.*
Herewith an example of what I try to do:
"Hello World!" "Hello
World!"
And here is what I get:
"Hello World!"
"Hello World!"
And because of different printing area limits and size of the font and the different font style, I can't just write these into one simple sentence including the correct number of spaces.
Quoting error messages exactly helps others to help you.
The error message reads:
DrawString: With XLineAlignment.BaseLine the height of the layout rectangle must be 0.
The text will be aligned at a line, therefore height must be 0. Yes, that's a line.
Use a different alignment if you specify a rectangle.
The TextLayout sample shows how to format text.
The Graphics sample also shows how to layout text (single lines of text, no automatic line breaks; the technique shown in the TextLayout sample handles line breaks automatically using the XTextFormatter class).
While trying to figure out how text positioning works with PdfSharp, I noticed that the DrawString() method writes on top of the Y coordinate that we specify.
If I wish to write at (0, 100)(x, y), this points to the lower-left corner while I thought this was the top-left corner coordinates. As a result, the text string Y coordinate that I should have specified is 100 + string.Height * .6.
PdfDocument pdfDoc = new PdfDocument();
PdfPage pdfPage = new pdfPage();
pdfPage.Size = PageSize.Letter;
pdfPage.Orientation = Orientation.Landscape;
pdfDoc.Pages.Add(pdfPage);
double posX = 0;
double posY = pdfPage.Height * .4093;
string helloString = "Hello"
string worldString = "World!"
XFont helloFont = new XFont("Helvetica", 25, XFontStyle.Regular);
XFont worldFont = new XFont("Helvetica", 270, XFontStyle.Bold);
using(var pdfGfx = XGraphics.FromPdfPage(pdfPage)) { // assuming the default Point UOM
XSize helloStringSize = pdfGfx.MeasureString(helloString, helloFont);
XSize worldStringSize = pdfGfx.MeasureString(worldString, worldFont);
pdfGfx.DrawString(helloString
, helloFont
, XBrushes.Black
, posX
, posY + helloStringSize.Height * .6
, XStringFormats.Default);
pdfGfx.DrawString(worldString
, worldFont
, XBrushes.Black
, pdfPage.Width * .3978
, posY + (worldStringSize.Height + helloStringSize.Height) * .6
, XStringFormats.Default);
}
You'll perhaps wonder why I only add 60% of the string size when I want to get my string written below my Y coordinate? That is because the full height of the font includes somekind of leap on top. So, the computing result will not be what is expected. On the other hand, you don't have to care about a leap if you need one. In my particular case, I don't require leap, so I must take it off the string's height.
If you feel like my explanation needs more accurate details, please feel free to either add them as comments or keep me informed so that I may include them.
Thanks!

How to get an outline view in sublime texteditor?

How do I get an outline view in sublime text editor for Windows?
The minimap is helpful but I miss a traditional outline (a klickable list of all the functions in my code in the order they appear for quick navigation and orientation)
Maybe there is a plugin, addon or similar? It would also be nice if you can shortly name which steps are neccesary to make it work.
There is a duplicate of this question on the sublime text forums.
Hit CTRL+R, or CMD+R for Mac, for the function list. This works in Sublime Text 1.3 or above.
A plugin named Outline is available in package control, try it!
https://packagecontrol.io/packages/Outline
Note: it does not work in multi rows/columns mode.
For multiple rows/columns work use this fork:
https://github.com/vlad-wonderkidstudio/SublimeOutline
I use the fold all action. It will minimize everything to the declaration, I can see all the methods/functions, and then expand the one I'm interested in.
I briefly look at SublimeText 3 api and view.find_by_selector(selector) seems to be able to return a list of regions.
So I guess that a plugin that would display the outline/structure of your file is possible.
A plugin that would display something like this:
Note: the function name display plugin could be used as an inspiration to extract the class/methods names or ClassHierarchy to extract the outline structure
If you want to be able to printout or save the outline the ctr / command + r is not very useful.
One can do a simple find all on the following grep ^[^\n]*function[^{]+{ or some variant of it to suit the language and situation you are working in.
Once you do the find all you can copy and paste the result to a new document and depending on the number of functions should not take long to tidy up.
The answer is far from perfect, particularly for cases when the comments have the word function (or it's equivalent) in them, but I do think it's a helpful answer.
With a very quick edit this is the result I got on what I'm working on now.
PathMaker.prototype.start = PathMaker.prototype.initiate = function(point){};
PathMaker.prototype.path = function(thePath){};
PathMaker.prototype.add = function(point){};
PathMaker.prototype.addPath = function(path){};
PathMaker.prototype.go = function(distance, angle){};
PathMaker.prototype.goE = function(distance, angle){};
PathMaker.prototype.turn = function(angle, distance){};
PathMaker.prototype.continue = function(distance, a){};
PathMaker.prototype.curve = function(angle, radiusX, radiusY){};
PathMaker.prototype.up = PathMaker.prototype.north = function(distance){};
PathMaker.prototype.down = PathMaker.prototype.south = function(distance){};
PathMaker.prototype.east = function(distance){};
PathMaker.prototype.west = function(distance){};
PathMaker.prototype.getAngle = function(point){};
PathMaker.prototype.toBezierPoints = function(PathMakerPoints, toSource){};
PathMaker.prototype.extremities = function(points){};
PathMaker.prototype.bounds = function(path){};
PathMaker.prototype.tangent = function(t, points){};
PathMaker.prototype.roundErrors = function(n, acurracy){};
PathMaker.prototype.bezierTangent = function(path, t){};
PathMaker.prototype.splitBezier = function(points, t){};
PathMaker.prototype.arc = function(start, end){};
PathMaker.prototype.getKappa = function(angle, start){};
PathMaker.prototype.circle = function(radius, start, end, x, y, reverse){};
PathMaker.prototype.ellipse = function(radiusX, radiusY, start, end, x, y , reverse/*, anchorPoint, reverse*/ ){};
PathMaker.prototype.rotateArc = function(path /*array*/ , angle){};
PathMaker.prototype.rotatePoint = function(point, origin, r){};
PathMaker.prototype.roundErrors = function(n, acurracy){};
PathMaker.prototype.rotate = function(path /*object or array*/ , R){};
PathMaker.prototype.moveTo = function(path /*object or array*/ , x, y){};
PathMaker.prototype.scale = function(path, x, y /* number X scale i.e. 1.2 for 120% */ ){};
PathMaker.prototype.reverse = function(path){};
PathMaker.prototype.pathItemPath = function(pathItem, toSource){};
PathMaker.prototype.merge = function(path){};
PathMaker.prototype.draw = function(item, properties){};