GetMap request return white image - wms

I just get a problem trying to display my map with GetMap request using Mapserver but it return a white image. I did search but i didn't found an answer :
My map file :
MAP
IMAGETYPE PNG
EXTENT -21 20 1 36
SIZE 700 400
IMAGECOLOR 255 255 255
PROJECTION
"init=epsg:4326"
END
OUTPUTFORMAT
NAME png
MIMETYPE image/png
DRIVER GD/PNG
EXTENSION png
IMAGEMODE PC256
TRANSPARENT FALSE
END
WEB
METADATA
"wms_title" "Dans Layers and Stuff"
"wms_onlineresource" "http://localhost:81/cgi-bin/mapserv.exe?"
"wms_enable_request" "*"
"wms_srs" "EPSG:4326"
"wms_feature_info_mime_type" "text/html"
"wms_format" "image/png"
END
END
LAYER
NAME map1
TYPE polygon
STATUS default
CONNECTIONTYPE postgis
CONNECTION "dbname=postgres host=localhost port=5432 user=postgres"
DATA "geom from comgeo"
PROJECTION
"init=epsg:4326"
END
METADATA
"wms_title" "map1"
END
PROCESSING "SCALE=AUTO"
CLASS
STYLE
COLOR 232 232 232
OUTLINECOLOR 32 32 32
END
END
END
END
And this the Link i used for my request :
http://localhost:81/cgi-bin/mapserv.exe?map=/wamp64/www/wordpress/map1.map&version=1.3.0&request=GetMap&CRS=EPSG:4326&bbox=-21,20,1,36&width=760&height=360&layers=map1&styles=&FORMAT=image/png&TRANSPARENT=TRUE
The BBox values are correct. Thank you

You appear to be missing SERVICE=WMS parameter on your URL.

I did solve the probleme when i replace epsg:4326 with CRS:84 and the URL :
http://localhost:81/cgi-bin/mapserv.exe?map=/wamp64/www/wordpress/map1.map&request=GetMap&SERVICE=WMS&version=1.3.0&CRS=CRS:84&bbox=-21,20,1,36&width=700&height=400&layers=map1&styles=&FORMAT=image/png&TRANSPARENT=TRUE

Version of WMS 1.1.1 and WMS 1.3.0 have different request parameter for coordinate system : SRS=EPSG:4326 for 1.1.1 and CRS=CRS:84 for 1.3.0
see mapserver wms

Related

Load custom package model to get model vocabulary in AllenNLP python interface

I'm trying to get the vocabulary from some publicly-available pre-trained models (that aren't mine) using the python interface of AllenNLP, using self.vocab. However, I'm running into problems trying to load in the model. I'm looking to get the vocabulary from the dygiepp models, using the following code:
from allennlp.models.model import Model
scierc_model = Model.from_archive('https://s3-us-west-2.amazonaws.com/ai2-s2-research/dygiepp/master/scierc.tar.gz')
However, I get the following error:
---------------------------------------------------------------------------
ConfigurationError Traceback (most recent call last)
/tmp/local/63381207/ipykernel_7616/3549263982.py in <module>
----> 1 scierc_model = Model.from_archive('https://s3-us-west-2.amazonaws.com/ai2-s2-research/dygiepp/master/scierc.tar.gz')
~/anaconda3/envs/dygiepp/lib/python3.7/site-packages/allennlp/models/model.py in from_archive(cls, archive_file, vocab)
480 from allennlp.models.archival import load_archive # here to avoid circular imports
481
--> 482 model = load_archive(archive_file).model
483 if vocab:
484 model.vocab.extend_from_vocab(vocab)
~/anaconda3/envs/dygiepp/lib/python3.7/site-packages/allennlp/models/archival.py in load_archive(archive_file, cuda_device, overrides, weights_file)
231 # Instantiate model and dataset readers. Use a duplicate of the config, as it will get consumed.
232 dataset_reader, validation_dataset_reader = _load_dataset_readers(
--> 233 config.duplicate(), serialization_dir
234 )
235 model = _load_model(config.duplicate(), weights_path, serialization_dir, cuda_device)
~/anaconda3/envs/dygiepp/lib/python3.7/site-packages/allennlp/models/archival.py in _load_dataset_readers(config, serialization_dir)
267
268 dataset_reader = DatasetReader.from_params(
--> 269 dataset_reader_params, serialization_dir=serialization_dir
270 )
271 validation_dataset_reader = DatasetReader.from_params(
~/anaconda3/envs/dygiepp/lib/python3.7/site-packages/allennlp/common/from_params.py in from_params(cls, params, constructor_to_call, constructor_to_inspect, **extras)
586 "type",
587 choices=as_registrable.list_available(),
--> 588 default_to_first_choice=default_to_first_choice,
589 )
590 subclass, constructor_name = as_registrable.resolve_class_name(choice)
~/anaconda3/envs/dygiepp/lib/python3.7/site-packages/allennlp/common/params.py in pop_choice(self, key, choices, default_to_first_choice, allow_class_names)
322 """{"model": "my_module.models.MyModel"} to have it imported automatically."""
323 )
--> 324 raise ConfigurationError(message)
325 return value
326
ConfigurationError: dygie not in acceptable choices for dataset_reader.type: ['babi', 'conll2003', 'interleaving', 'multitask', 'multitask_shim', 'sequence_tagging', 'sharded', 'text_classification_json']. You should either use the --include-package flag to make sure the correct module is loaded, or use a fully qualified class name in your config file like {"model": "my_module.models.MyModel"} to have it imported automatically.
The error describes how to fix the error from the command line, but not in the python interface. I additionally tried adding the line import dygie to my code to import the missing package, but that didn't solve the problem.
Wondering if anyone knows how to get around this?
To run this model, you'll need to have the code from this repo: https://github.com/dwadden/dygiepp.
In particular, you need to import the DyGIE dataset reader from here: https://github.com/dwadden/dygiepp/blob/master/dygie/data/dataset_readers/dygie.py#L29

Hyperparameter tuning using tensorboard.plugins.hparams api with custom loss function

I am building a neural network with my own custom loss function (pretty long and complicated). My network is unsupervised so my input and expected output are identical and also at the moment I am using one single input (just trying to optimize the loss for a single input).
I am trying to use tensorboard.plugins.hparams api for hyperparameter tuning and don't know how to incorporate my custom loss function there. I'm trying to follow the code suggested on the Tensorflow 2.0 website.
This is what the website suggests:
HP_NUM_UNITS = hp.HParam('num_units', hp.Discrete([16, 32]))
HP_DROPOUT = hp.HParam('dropout', hp.RealInterval(0.1, 0.2))
HP_OPTIMIZER = hp.HParam('optimizer', hp.Discrete(['adam', 'sgd']))
METRIC_ACCURACY = 'accuracy'
with tf.summary.create_file_writer('logs/hparam_tuning').as_default():
hp.hparams_config(
hparams=[HP_NUM_UNITS, HP_DROPOUT, HP_OPTIMIZER],
metrics=[hp.Metric(METRIC_ACCURACY, display_name='Accuracy')],
)
I need to change that as I don't want to use the dropout layer, so I can just delete that. In terms of the METRIC_ACCURACY, I don't want to use accuracy as that has no use in my model but rather use my custom loss function. If I were to do the regular fit model it would look like this:
model.compile(optimizer=adam,loss=dl_tf_loss, metrics=[dl_tf_loss])
So I tried to change the suggested code into the following code but I get an error and am wondering how I should change it so that it suits my needs. Here is what I tried:
HP_NUM_UNITS = hp.HParam('num_units', hp.Discrete([16, 32]))
HP_OPTIMIZER = hp.HParam('optimizer', hp.Discrete(['adam', 'sgd']))
#METRIC_LOSS = dl_tf_loss
with tf.summary.create_file_writer('logs/hparam_tuning').as_default():
hp.hparams_config(hparams=[HP_NUM_UNITS, HP_OPTIMIZER],metrics=
[hp.Metric(dl_tf_loss, display_name='Loss')])
It gives me the following error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-26-27d079c6be49> in <module>()
5
6 with tf.summary.create_file_writer('logs/hparam_tuning').as_default():
----> 7 hp.hparams_config(hparams=[HP_NUM_UNITS, HP_OPTIMIZER],metrics=[hp.Metric(dl_tf_loss, display_name='Loss')])
8
3 frames
/usr/local/lib/python3.6/dist-packages/tensorboard/plugins/hparams/summary_v2.py in hparams_config(hparams, metrics, time_created_secs)
127 hparams=hparams,
128 metrics=metrics,
--> 129 time_created_secs=time_created_secs,
130 )
131 return _write_summary("hparams_config", pb)
/usr/local/lib/python3.6/dist-packages/tensorboard/plugins/hparams/summary_v2.py in hparams_config_pb(hparams, metrics, time_created_secs)
161 domain.update_hparam_info(info)
162 hparam_infos.append(info)
--> 163 metric_infos = [metric.as_proto() for metric in metrics]
164 experiment = api_pb2.Experiment(
165 hparam_infos=hparam_infos,
/usr/local/lib/python3.6/dist-packages/tensorboard/plugins/hparams/summary_v2.py in <listcomp>(.0)
161 domain.update_hparam_info(info)
162 hparam_infos.append(info)
--> 163 metric_infos = [metric.as_proto() for metric in metrics]
164 experiment = api_pb2.Experiment(
165 hparam_infos=hparam_infos,
/usr/local/lib/python3.6/dist-packages/tensorboard/plugins/hparams/summary_v2.py in as_proto(self)
532 name=api_pb2.MetricName(
533 group=self._group,
--> 534 tag=self._tag,
535 ),
536 display_name=self._display_name,
TypeError: <tensorflow.python.eager.def_function.Function object at 0x7f9f3a78e5c0> has type Function, but expected one of: bytes, unicode
I also tried running the following code:
with tf.summary.create_file_writer('logs/hparam_tuning').as_default():
hp.hparams_config(hparams=[HP_NUM_UNITS, HP_OPTIMIZER],metrics=
[dl_tf_loss])
but got the following error:
AttributeError Traceback (most recent call last)
<ipython-input-28-6778bdf7f1b1> in <module>()
8
9 with tf.summary.create_file_writer('logs/hparam_tuning').as_default():
---> 10 hp.hparams_config(hparams=[HP_NUM_UNITS, HP_OPTIMIZER],metrics=[dl_tf_loss])
2 frames
/usr/local/lib/python3.6/dist-packages/tensorboard/plugins/hparams/summary_v2.py in <listcomp>(.0)
161 domain.update_hparam_info(info)
162 hparam_infos.append(info)
--> 163 metric_infos = [metric.as_proto() for metric in metrics]
164 experiment = api_pb2.Experiment(
165 hparam_infos=hparam_infos,
AttributeError: 'Function' object has no attribute 'as_proto'
Would greatly appreciate any help.
Thanks in advance!
I figured it out.
The original METRIC_ACCURACY that I changed to METRIC_LOSS is apparently just the name, I needed to write 'tf_dl_loss' as a string and not as the function.
In the proceeding parts of the tuning, I needed to anyway write my fit command, there I inserted the actual loss function as I showed in my example of the regular fit function.
Highly recommend this as a way of tuning the hyperparameters.
You might be interested by this demo. Compiling the model with dl_tf_loss in the metric will waste time. It is possible to let hp.Metric know about other recorded summaries in different directories using the group argument.

Cannot send base64 String to PubNub

I am using PyCamera module of Raspberry Pi to capture an image and store as .jpg.
first encoding the image using base64.encodestring(). but while sending encoded string to PubNub server, I get error on my_publish_callback as
('ERROR: ', 'Expecting value: line 1 column 1 (char 0)')
('ERROR: ', JSONDecodeError('Expecting value: line 1 column 1 (char 0)',))
I have tried using base64.b64encode() but still get the same errors. I have tried the script in python 2 and 3;
def my_publish_callback(envelope, status):
if not status.is_error():
pass # Message successfully published to specified channel.
else:
#print("recv: ", envelope)
print("ERROR: ", status.error_data.information)
print("ERROR: ", status.error_data.exception)
def publish(channel, msg):
pubnub.publish().channel(channel).message(msg).async(my_publish_callback)
def captureAndSendImage():
camera.start_preview()
time.sleep(2)
camera.capture("/home/pi/Desktop/image.jpg")
camera.stop_preview()
with open("/home/pi/Desktop/image.jpg", "rb") as f:
encoded = base64.encodestring(f.read())
publish(myChannel, str(encoded))
I am not able to find or print full error traceback so that I can get some more clues about where the error is occurring. But it looks like PubNub is trying to parse the data in JSON, and its failing.
I realized the .jpg file size is 154KB, whereas PubNub max packet size is 32KB, so that should clearly say it all. PubNub recommends to send large messages by splitting them and re-arranging them in subscriber-end. Thanks #Craig for referring to that link, Its useful though support.pubnub.com/support/discussions/topics/14000006326

mPDF error on Codeigniter

I tried to convert a html page to pdf and was decided to use mPDF, I follow what the documentation does. When running the code, it does not prompt out the PDF to ask for save. Btw I get those error code.
Here is the code from Controller.
//this data will be passed on to the view
$data['the_content']='mPDF and CodeIgniter are cool!';
//load the view, pass the variable and do not show it but "save" the output into $html variable
$html=$this->load->view('ajax/pdf_output', $data, true);
//this the the PDF filename that user will get to download
$pdfFilePath = "the_pdf_output.pdf";
//load mPDF library
$this->load->library('m_pdf');
//actually, you can pass mPDF parameter on this load() function
$pdf = $this->m_pdf->load();
//generate the PDF!
$pdf->WriteHTML($html);
//offer it to user via browser download! (The PDF won't be saved on your server HDD)
$pdf->Output($pdfFilePath, "I");
Below is the result i get:
%PDF-1.4 %���� 3 0 obj <> /Contents 4 0 R>> endobj 4 0 obj <> stream x��P]O�#���㓚����^�1�h�7�C��B(h���sW�Fs����vvv�B')�ձCgha�6��Mp�6� �H�U[P��{��-[�uz��#��뮉�r�#Υ�9�R���'�J�h&���e� �J�YW�f����\���/�m�Ӷ�����J.w���j��N�ގ��^�=f!��ƲO����o�92yh�m���9� �e��[��#�3���?u�R%_�¿�)�X|jt2H׆��+��S��™9%�R��:��ƒ7��m��Z����9n� endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 6 0 obj <> endobj 7 0 obj <> endobj 8 0 obj <> stream /CIDInit /ProcSet findresource begin 12 dict begin begincmap /CIDSystemInfo <> def /CMapName /Adobe-Identity-UCS def /CMapType 2 def 1 begincodespacerange <0000> endcodespacerange 1 beginbfrange <0000> <0000> endbfrange endcmap CMapName currentdict /CMap defineresource pop end end endstream endobj 9 0 obj <> endobj 10 0 obj < >> /FontFile2 12 0 R >> endobj 11 0 obj <> stream x����V�����Qfd%{dT*�l-�Ȉ��_����s��ڥ����}��#;���t���:��Nt�S�n�3�m�s��B��h��JW���nt�[��Nw�^�{��&�l�GM7�l�{���z��^4��^��7��]���B�-��J���V[�K�}�[}�G?��f���V���n���w�� endstream endobj 12 0 obj <> stream x��| \TU��9��;�.�zqIe�]ce�t��apfQQ�q�qGKSS+5-K+Ӟ�z�6�35���gi���wν3d=��}����g�s�=������\0�B��4#+76�r����=\��}�O��:�p <7�r���G~BHH���EŖ�j��B�C_U��W /� q<��U�}��<�!��t�Qo��ۀPdwXN���<���X���<�~]��Po3oC(��_��gW��Ўz��r��8�XR!<����+�vG�B4�Q��� ����Z�<���(��^�Dhk��#��r'WQ����h4�F��i�Fw���H$�]�3�$77kBi(��e��A�=7�"凨����C���]D��.=�onf�577���l��$��y#����? ��CA(�G!(���#��:�Ѓ��uE݀�p�"Qw�z�����F}P4��bP,����8�EP<���h����h�yQJF)H�R�(4��1h,JG(e�l4��\��ƣ|4MD�#�S�T4 =���H:�Ev$���-�|�tdF3�r��w�\�����>�����~�N��0OZ�ˀ���;0����>�H����m� $Z�|�^t�E��r�Uo�l/�ì-���a^� �$#�΢O�b�A5h ��L�]��tx1�� ��$d�Y�Y�� Jf��,��W�qo�Cf�"<$�a2z�"�8>=�'�˧� s��*/z[�*�{��#��x���op:.��O�A{�?p�Yz����������-ޡ��!y�� }kP&� T�]��H"0���� Qi�c �&�oL ���Q򒏡�c���������Ҥc�C�H��11*�� ��=6{�|��.EE��H��܉�dO� �����[ ,~O�5�֓��І,>�lozG��s�� ���6Mo��^�m���� 0P�!,T�#DK�"�����SS�ku��#�%�33�̐�hz��I�z�v�zNG��`���N���"�a�[
Anyone can tell me what happening with this?
it looks like the "I" parameter is causing trouble because the browser doesn't recognize your file
according to the docu you've the following Possibilities:
I: send the file inline to the browser. The plug-in is used if available. The name given by $filename is used when one selects the “Save as” option on the link generating the PDF.
D: send to the browser and force a file download with the name given by $filename.
F: save to a local file with the name given by $filename (may include a path).
S: return the document as a string. $filename is ignored.
try something like that :
$pdf->Output($pdfFilePath, "D");
die;
or on the other hand you can try to add some header to tell the browser explicitly this is a pdf document
header('Content-Type: application/pdf');
$pdf->Output($pdfFilePath, "I");
die;
because it could be CIs outpout class overwrites MPDF's header (but this is just a hunch)
$html=$this->load->view("ajax/pdf_output",$data,true);
//load mPDF library
$this->load->library('m_pdf');
//generate the PDF from the given html
$this->m_pdf->pdf->WriteHTML($html);
//download it.
ob_clean();
$this->m_pdf->pdf->Output($pdfFilePath,'F');
check your folder.....
If you want show download dialogue your need to place below code
$filename = time()."_order.pdf"; //your file name
$html = $this->load->view('unpaid_voucher2',$data,true);
/// $data variable is your dynamic data if you have no dynmic data then you can pass empty instead of variable like.
$html = $this->load->view('unpaid_voucher2','',true);
$this->load->library('M_pdf');
$this->m_pdf->pdf->WriteHTML($html);
//For download pass D and save on server pass F.
$this->m_pdf->pdf->Output("./uploads/".$filename, "D");
Here is full configuration to integrate mpdf into codeigniter
The string is a binary PDF representation and its presence means Content-type: application/pdf header is not sent correctly or it is
overriden by your code or setup. Most likely by text/plain or text/html.
Try to figure out these:
Are you resetting Content-type header in PHP code somewhere after calling the mPDF Output method?
Is your server forcing a different Content-type somewhere in your setup?
Does your browser support displaying application/pdf Content-type directly?
Given that the D Output mode gives you the same result, I'd guess the Content-type header is being overriden somewhere after calling the Output method, presumably by CodeIgniter.

MapServer SOS (Sensor Observation Service) Configuration

I tried to set up MapServer SOS but I faced a problem: the SOS doesn't return anything. You may see the map file I have created below:
MAP
NAME "SOS_DEMO"
STATUS ON
SIZE 400 300
EXTENT -180 -90 180 90
UNITS METERS
SHAPEPATH "C:\ms4w\apps\tutorial\data"
IMAGECOLOR 255 255 255
WEB
IMAGEPATH "C:\ms4w\apps\tutorial\templates"
IMAGEURL "C:\ms4w\apps\tutorial\images"
METADATA
"sos_onlineresource" "http://127.0.0.1:8282/cgi-bin/mapserv.exe?map=c:/ms4w/mysos.map?"
"sos_title" "My SOS Demo Server"
"sos_srs" "EPSG:4326"
"sos_enable_request" "*"
END
END
PROJECTION
"init=epsg:4326"
END
LAYER
NAME "sos_point"
METADATA
"sos_procedure" "ifgi-sensor-1"
"sos_offering_id" "WQ1289"
"sos_observedproperty_id" "Water Quality"
"sos_describesensor_url" "http://127.0.0.1:8181/DescribeSensor.xml"
END
TYPE POINT
STATUS ON
DATA 'sospoint'
PROJECTION
"init=epsg:4326"
END
CLASS
NAME 'sospoint'
STYLE
COLOR 255 128 128
END
END
END
END
As you see, I tried to retrieve sensor data from a shapefile. The message returned by the SOS is:
<om:ObservationCollection xmlns:gml="http://www.opengis.net/gml" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:swe="http://www.opengis.net/swe/1.0.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sos="http://www.opengis.net/sos/1.0" xmlns:ms="http://mapserver.gis.umn.edu/mapserver" xmlns:om="http://www.opengis.net/om/1.0" gml:id="WQ1289" xsi:schemaLocation="http://www.opengis.net/om/1.0 http://schemas.opengis.net/om/1.0.0/om.xsd http://mapserver.gis.umn.edu/mapserver http://127.0.0.1:8282/cgi-bin/mapserv.exe?map=c:/ms4w/mysos.map?service=WFS&version=1.1.0&request=DescribeFeatureType&typename=urban">
<om:member>
<om:Observation>
<om:procedure xlink:href="urn:ogc:def:procedure:ifgi-sensor-1"/>
<om:observedProperty>
<swe:CompositePhenomenon gml:id="Water Quality" dimension="3">
<swe:component xlink:href="urn:ogc:def:property:OGC-SWE:1:Id"/>
<swe:component xlink:href="urn:ogc:def:property:OGC-SWE:1:sensor_nam"/>
<swe:component xlink:href="urn:ogc:def:property:OGC-SWE:1:sensor_val"/>
</swe:CompositePhenomenon>
</om:observedProperty>
<om:resultDefinition>
<swe:DataBlockDefinition>
<swe:components>
<swe:DataRecord/>
</swe:components>
<swe:encoding>
<swe:TextBlock tokenSeparator="," blockSeparator=" " decimalSeparator="."/>
</swe:encoding>
</swe:DataBlockDefinition>
</om:resultDefinition>
<om:result></om:result>
</om:Observation>
</om:member>
</om:ObservationCollection>
Although I put 6 observations into the shapefile but the SOS doesn't return any. Would you please let me know what I should do to resolve the problem?!
Thanks,
Ebrahim
Perhaps better ask here? https://gis.stackexchange.com/