How to determine in which esriTransformDirection we need to use in ArcObject IGeometry5 ProjectEx - esri

I am working on a project in which i need to calculate the points form on CRS to another, but as we the source and target CRS are only determine on runtime.
ISpatialReference source = GCS_North_American_1983
ISpatialReference target = UTM Zone 13 North (108 W - 102 W Longitude)
IEnvelope extent = rasterLayer.VisibleExtent;
Console.WriteLine(extent.XMax); == -97.815540361118
Console.WriteLine(extent.XMin); == -102.045540576002
Console.WriteLine(extent.YMax); == 39.933228902485
Console.WriteLine(extent.YMin); == 37.113228759229
IGeoTransformation geoTransformation = "NAD_1927_To_NAD_1983_NADCON"
geoTransformationOperationSet.Set(esriTransformDirection.esriTransformForward, geoTransformation);
geoTransformationOperationSet.Set(esriTransformDirection.esriTransformReverse, geoTransformation);
//So we need to go in reverse order. as source is in NAD83 and Target is in NAD27. and returns correct results matched with ArcMap but going forward results wrong output.
geometry.ProjectEx(target, esriTransformDirection.esriTransformReverse, geoTransformation, false, 0.0, 0.0);
Console.WriteLine(extent.XMax); == 1138797.89197912
Console.WriteLine(extent.XMin); == 752503.366222885
Console.WriteLine(extent.YMax); == 4444925.18943959
Console.WriteLine(extent.YMin); == 4111314.85519851
if we do the forward transformation return incorrect result.
1138738.17611084
752424.161510695
4444923.04572637
4111317.16066915
So how can I determine which direction we need to use? Like forward/reverse. Is there any way we can find out using arcobject API return use fwd or reverse. I looked into the IGeoTransformation but no success, there are many different predefined GeoTransformation which can use in both fwd or reverse if supported.
Thanks.

Related

Trying to get property 'path' of non-object

Hello I am having the above error in production but all works well in development. I am using the code bellow to get the path to the main image for the property but it defaults into the else despite the if not being false plus the else does not find the paths even when dump shows that the object has been returned
//check if there are hotels in the selected destination
if($hotels->isNotEmpty()){
//Loop through the hotels
foreach($hotels as $hotel){
//get hotels main image
$banner = Photo::where(['p_id'=>$hotel->id])->where(['is_main'=>1])->first();
$altbanner = Photo::where(['p_id'=>$hotel->id])->first();
$banner_path = "";
$altText = "";
if($banner!=null){
$banner_path = $banner->path;
$altText = $banner->alt_text;
}else{
$banner_path = $altbanner->path;
$altText = $altbanner->alt_text;
}
Have you checked your database if each hotel has an image? Based on your question and explanation, there is a part of the for each that returns null for the image hence the if part fails and the else return the error. If that is the case then you may want to check and sort it by uploading the image or modifying your checks to handle cases where no image is found.
I think the way you are using the where clause isn't right
foreach($hotels as $hotel){
//get hotels main image
$banner = Photo::where('p_id',$hotel->id)->where('is_main',1)->first();
$altbanner = Photo::where('p_id',$hotel->id)->first();
// .....
if($banner){
$banner_path = $banner->path;
// ......

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 );

How to create fishnet in arcgis engine?

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.

AVAudioUnitEQ / .BandPass filter doesn't work

I can't get the AVAudioUnitEQ to work.
Here's a piece of code that should filter out everything except 659.255Hz +/-0.05 octaves:
// Create Audio Engine
var audioEngine = AVAudioEngine()
// Create Equalizer Node
var equalizerNode = AVAudioUnitEQ(numberOfBands: 1)
var epualizerParameters: AVAudioUnitEQFilterParameters = equalizerNode.bands.first as AVAudioUnitEQFilterParameters
epualizerParameters.filterType = .BandPass
epualizerParameters.frequency = 659.255
epualizerParameters.bandwidth = 0.05
epualizerParameters.bypass = false
audioEngine.attachNode(equalizerNode)
// Configure Audio Engine
var format = audioEngine.inputNode.inputFormatForBus(0)
audioEngine.connect(audioEngine.inputNode, to: equalizerNode, format: format)
audioEngine.connect(equalizerNode, to: audioEngine.outputNode, format: format)
// Start Audio Engine
var error:NSError?
audioEngine.startAndReturnError(&error)
However, when I run it, put on my headphones and sing into the microphone, I can hear myself loud and clear.
Now, according to Wikipedia, the Band Pass filter is:
... a device that passes frequencies within a certain range and
rejects (attenuates) frequencies outside that range.
What am I doing wrong? I want to filter out everything except given frequency range.
It was your EQ params.
I created a github project with sliders and switches. You can hear the difference.
Try it.
This works in my project which uses a playerNode.
var format = engine.mainMixerNode.outputFormatForBus(0)
engine.connect(playerNode, to: EQNode, format: format )
engine.connect(EQNode, to: engine.mainMixerNode, format: format)
I see you're using the engine's inputNode. Try swapping out these few lines (hook into the mixer instead of the outputNode) and let us know if it works.

Combinations and Permutations of Photoshop Layers?

This one is a big one
I have a Photoshop document that has 8 Layers in it. I need to create a way to use those 8 layers and create certain combinations depending on the rules below...
Example:
{1,2,3} {1,2,4} {1,2,5} {1,2,6} {1,2,7} {1,2,8} {1,3,4} {1,3,5} {1,3,6} {1,3,7} {1,3,8} {1,4,5} {1,4,6} {1,4,7} {1,4,8} {1,5,6} {1,5,7} {1,5,8} {1,6,7} {1,6,8} {1,7,8} {2,3,4} {2,3,5} {2,3,6} {2,3,7} {2,3,8} {2,4,5} {2,4,6} {2,4,7} {2,4,8} {2,5,6} {2,5,7} {2,5,8} {2,6,7} {2,6,8} {2,7,8} {3,4,5} {3,4,6} {3,4,7} {3,4,8} {3,5,6} {3,5,7} {3,5,8} {3,6,7} {3,6,8} {3,7,8} {4,5,6} {4,5,7} {4,5,8} {4,6,7} {4,6,8} {4,7,8} {5,6,7} {5,6,8} {5,7,8} {6,7,8}
Using the above combination, each combination needs to be saved out as an image. SO if you take one of the above combinations for instance, {3,6,8}. Photoshop should use layers 3,6,8 to create a new image or layer comprising of those three segments.
Not sure how to start this. So far I have worked out all possible combinations using this great site:
http://www.mathsisfun.com/combinatorics/combinations-permutations-calculator.html
You can write a script to turn off the layers you don't want and then save to a new file.
to turn a layer off:
var doc = app.activeDocument;
var lyr = doc.artLayers[index];
lyr.visible = false;
The document object has a 'saveas' method that you can use to specify the file type and location that you require the output to be.
More info can be found in the Photoshop Javascript Reference pdf in your photoshop installation directory.
This function will do what you want:
gimmeTheseLayers("3", "5", "spoon");
function gimmeTheseLayers(l1, l2, l3)
{
for (var i = 0; i < numOfLayers -1; i++)
{
// look for the appropriate layer
var l = app.activeDocument.layers[i];
if (l.name == l1 || l.name == l2 || l.name == l3) l.visible = true;
else l.visible = false;
// keep the background layer on
if (l.isBackgroundLayer == true) l.visible = true;
}
}
Just feed it the layer name (in quotes) and it'll keep those layers visible, it'll switch off all the rest except the background. Won't work with layersets!